package com.kurumi.medical.service.impl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.kurumi.medical.component.Const;
import com.kurumi.medical.component.MyConfig;
import com.kurumi.medical.datasource.TargetDataSource;
import com.kurumi.medical.log.ExceptionLog;
import com.kurumi.medical.mapper.BloodTransfusionMapper;
import com.kurumi.medical.mapper.CitizensInfoMapper;
import com.kurumi.medical.mapper.Export305DataMapper;
import com.kurumi.medical.mapper.ExportDataMapper;
import com.kurumi.medical.mapper.FirstLevelMedicalMapper;
import com.kurumi.medical.mapper.HospNoteBasicJsonMapper;
import com.kurumi.medical.mapper.HospNoteVersionMapper;
import com.kurumi.medical.mapper.HospitalizationNoteMapper;
import com.kurumi.medical.mapper.InsuranceAccountsMapper;
import com.kurumi.medical.mapper.PatVisitMapper;
import com.kurumi.medical.mapper.TreatmentTraceMapper;
import com.kurumi.medical.model.HospitalVisitBasicInfo;
import com.kurumi.medical.model.HospitalVisitCostInfo;
import com.kurumi.medical.model.HospitalVisitCostRecord;
import com.kurumi.medical.model.HospitalVisitCureInfo;
import com.kurumi.medical.model.HospitalVisitCureWorker;
import com.kurumi.medical.model.HospitalVisitDiagAccordRecord;
import com.kurumi.medical.model.HospitalVisitDiseaseDiagInfo;
import com.kurumi.medical.model.HospitalVisitDiseaseDiagRecord;
import com.kurumi.medical.model.HospitalVisitDoctorAdviceStandingInfo;
import com.kurumi.medical.model.HospitalVisitDoctorAdviceStandingItem;
import com.kurumi.medical.model.HospitalVisitDoctorAdviceStandingRecord;
import com.kurumi.medical.model.HospitalVisitDoctorAdviceTemporaryInfo;
import com.kurumi.medical.model.HospitalVisitDoctorAdviceTemporaryItem;
import com.kurumi.medical.model.HospitalVisitDoctorAdviceTemporaryRecord;
import com.kurumi.medical.model.HospitalVisitDrugAllergyInfo;
import com.kurumi.medical.model.HospitalVisitDrugAllergyRecord;
import com.kurumi.medical.model.HospitalVisitExaminationReportsInfo;
import com.kurumi.medical.model.HospitalVisitExaminationReportsItem;
import com.kurumi.medical.model.HospitalVisitExaminationReportsRecord;
import com.kurumi.medical.model.HospitalVisitInfectionInfo;
import com.kurumi.medical.model.HospitalVisitInfectionRecord;
import com.kurumi.medical.model.HospitalVisitInfusionBloodElement;
import com.kurumi.medical.model.HospitalVisitInfusionBloodInfo;
import com.kurumi.medical.model.HospitalVisitInfusionBloodRecord;
import com.kurumi.medical.model.HospitalVisitIntensiveCareInfo;
import com.kurumi.medical.model.HospitalVisitNurseInfo;
import com.kurumi.medical.model.HospitalVisitOperateInfo;
import com.kurumi.medical.model.HospitalVisitOperateRecord;
import com.kurumi.medical.model.HospitalVisitOperateWorker;
import com.kurumi.medical.model.HospitalVisitPressureSoreInfo;
import com.kurumi.medical.model.HospitalVisitProgressNote;
import com.kurumi.medical.model.HospitalVisitRecordSheet;
import com.kurumi.medical.model.HospitalVisitTransferDeptInfo;
import com.kurumi.medical.model.HospitalVisitTransferDeptRecord;
import com.kurumi.medical.param.Report;
import com.kurumi.medical.param.ReportItem;
import com.kurumi.medical.param.ReportRoot;
import com.kurumi.medical.pojo.Blood;
import com.kurumi.medical.pojo.CitizensInfo;
import com.kurumi.medical.pojo.FirstLevelMedical;
import com.kurumi.medical.pojo.HospNoteVersion;
import com.kurumi.medical.pojo.HospitalizationNote;
import com.kurumi.medical.pojo.PatVisit;
import com.kurumi.medical.pojo.PatVisitKey;
import com.kurumi.medical.pojo.TreatmentTrace;
import com.kurumi.medical.pojo.User;
import com.kurumi.medical.service.HospNoteBasicJsonService;
import com.kurumi.medical.service.HospitalVisit305Service;
import com.kurumi.medical.service.LogService;
import com.kurumi.medical.util.Analysis_Xml;
import com.kurumi.medical.util.DBUtil;
import com.kurumi.medical.util.DateUtil;
import com.kurumi.medical.util.ExceptionUtil;
import com.kurumi.medical.util.FileUtil;
import com.kurumi.medical.util.FtpClientUtil;
import com.kurumi.medical.util.HttpClientUtil;
import com.kurumi.medical.util.JsonUtil;
import com.kurumi.medical.util.PDFUtil;
import com.kurumi.medical.util.Result;
import com.kurumi.medical.util.StringUtil;
import com.kurumi.medical.util.Validator;
import com.kurumi.medical.vo.BloodTransfusionVO;
import com.kurumi.medical.vo.PatVisitVO;

@Service
public class Hospital305VisitServiceImpl implements HospitalVisit305Service {
	
	private Logger log =LoggerFactory.getLogger(this.getClass());

	private String idDocumentTypeCode = "SFZ";
	
	@Autowired
	private BloodTransfusionMapper bloodTransfusionMapper;
	
	@Autowired
	private LogService logService;
	
	//军人保障卡
	private String jr_idDocumentTypeCode = "JRBZK";

	private String hospitalCode = "49557184-0";
	
	@Autowired
	private TreatmentTraceMapper treatmentTraceMapper;
	
	@Autowired
	private HospNoteVersionMapper hospNoteVersionMapper;

	@Autowired
	private MyConfig myConfig;

	@Autowired
	private PatVisitMapper patVisitMapper;
	
	@Autowired
	private ExportDataMapper exportDataMapper;

	@Autowired
	private Export305DataMapper export305DataMapper;

	@Autowired
	private CitizensInfoMapper patientMapper;

	@Autowired
	private FirstLevelMedicalMapper firstLevelMedicalMapper;

	@Autowired
	private HospitalizationNoteMapper hospitalizationNoteMapper;

	@Autowired
	private HospNoteBasicJsonMapper hospNoteBasicJsonMapper;
	
	@Autowired
	private InsuranceAccountsMapper insuranceAccountsMapper;
	
	@Autowired
	private HospNoteBasicJsonService hospNoteBasicJsonService;

	@Override
	public Result getDatasByOracle(String mrId, Integer visitNumber) {
		// TODO Auto-generated method stub
		Result hospitalVisitFillInfos = getHospitalVisitFillInfoByOracle(mrId, visitNumber);
		return hospitalVisitFillInfos;
	}

	@Override
	public List<Map<String, Object>> getDatasByOracle() {
		// TODO Auto-generated method stub
		List<Map<String, Object>> hospitalVisitFillInfos = getHospitalVisitFillInfoByOracle();
		return hospitalVisitFillInfos;
	}

	@SuppressWarnings("unchecked")
	private List<Map<String, Object>> getHospitalVisitFillInfoByOracle() {
		List<Map<String, Object>> hospitalVisitInfos = export305DataMapper.getHospitalVisit305InfoByOracle();
		List<Map<String, Object>> hospitalVisitFillInfos = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> hospitalVisitInfo : hospitalVisitInfos) {
			Map<String, Object> hospitalVisitFillInfo = new HashMap<String, Object>();
			String visitGuid = StringUtil.getId();
			HospitalVisitBasicInfo basicInfo = new HospitalVisitBasicInfo();
			basicInfo.setVisitGuid(visitGuid);
			basicInfo.setPatientName((String) hospitalVisitInfo.get("PATIENTNAME"));
			basicInfo.setSexCode((String) hospitalVisitInfo.get("SEXCODE"));
			basicInfo.setSexName((String) hospitalVisitInfo.get("SEXNAME"));
			String birthdayStr = StringUtil.meaningStr((String) hospitalVisitInfo.get("BIRTHDAY"));
			if (birthdayStr != null) {
				try {
					Date birthday = DateUtil.dateParse(birthdayStr);
					basicInfo.setBirthday(birthday);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			basicInfo.setHospitalCode(hospitalCode);
			basicInfo.setIdDocumentTypeCode(idDocumentTypeCode);
			basicInfo.setIdDocumentTypeName("身份证");
			basicInfo.setIdNumber((String) hospitalVisitInfo.get("IDNUMBER"));
			basicInfo.setNationalityCode((String) hospitalVisitInfo.get("NATIONALITYCODE"));
			basicInfo.setNationalityName((String) hospitalVisitInfo.get("NATIONALITYNAME"));
			basicInfo.setNationCode((String) hospitalVisitInfo.get("NATIONCODE"));
			basicInfo.setNationName((String) hospitalVisitInfo.get("NATIONNAME"));
			basicInfo.setBirthAddressCode((String) hospitalVisitInfo.get("BIRTHADDRESSCODE"));
			basicInfo.setBirthAddress((String) hospitalVisitInfo.get("BIRTHADDRESS"));

			basicInfo.setMarriageCode((String) hospitalVisitInfo.get("MARRIAGECODE"));
			basicInfo.setMarriageName((String) hospitalVisitInfo.get("MARRIAGENAME"));

			basicInfo.setProfessionCode((String) hospitalVisitInfo.get("PROFESSIONCODE"));
			basicInfo.setProfessionName((String) hospitalVisitInfo.get("PROFESSIONNAME"));

			basicInfo.setPermanentAddress((String) hospitalVisitInfo.get("PERMANENTADDRESS"));
			basicInfo.setPermanentAddressPostCode((String) hospitalVisitInfo.get("PERMANENTADDRESSPOSTCODE"));

			basicInfo.setLinkManName((String) hospitalVisitInfo.get("LINKMANNAME"));
			basicInfo.setLinkManAddress((String) hospitalVisitInfo.get("LINKMANADDRESS"));

			basicInfo.setLinkManPhone((String) hospitalVisitInfo.get("LINKMANPHONE"));
			basicInfo.setLinkManRelativeRelationCode((String) hospitalVisitInfo.get("LINKMANRELATIVERELATIONCODE"));
			basicInfo.setLinkManRelativeRelationName((String) hospitalVisitInfo.get("LINKMANRELATIVERELATIONNAME"));

			basicInfo.setOnlyId((String) hospitalVisitInfo.get("ONLYID"));
			basicInfo.setMrId((String) hospitalVisitInfo.get("MRID"));
			BigDecimal visitNumber = (BigDecimal) hospitalVisitInfo.get("VISITNUMBER");
			if (visitNumber != null) {
				basicInfo.setVisitNumber(visitNumber);
			}

			String inHospitalDateTimeStr = StringUtil.meaningStr((String) hospitalVisitInfo.get("INHOSPITALDATETIME"));
			if (inHospitalDateTimeStr != null) {
				try {
					Date inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, inHospitalDateTimeStr);
					basicInfo.setInHospitalDateTime(inHospitalDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			basicInfo.setInDeptCode((String) hospitalVisitInfo.get("INDEPTCODE"));
			basicInfo.setInDeptName((String) hospitalVisitInfo.get("INDEPTNAME"));
			basicInfo.setOutDeptCode((String) hospitalVisitInfo.get("OUTDEPTCODE"));
			basicInfo.setOutDeptName((String) hospitalVisitInfo.get("OUTDEPTNAME"));

			String outHospitalDateTimeStr = StringUtil
					.meaningStr((String) hospitalVisitInfo.get("OUTHOSPITALNDATETIME"));
			if (outHospitalDateTimeStr != null) {
				try {
					Date outHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, outHospitalDateTimeStr);
					basicInfo.setOutHospitalDateTime(outHospitalDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			basicInfo.setOutHospitalTypeCode((String) hospitalVisitInfo.get("OUTHOSPITALTYPECODE"));
			basicInfo.setOutHospitalTypeName((String) hospitalVisitInfo.get("OUTHOSPITALTYPENAME"));

			basicInfo.setWorkUnitName((String) hospitalVisitInfo.get("WORKUNITNAME"));

			String clinicalReceptionDateTimeStr = StringUtil
					.meaningStr((String) hospitalVisitInfo.get("CLINICALRECEPTIONDATETIME"));
			if (clinicalReceptionDateTimeStr != null) {
				try {
					Date clinicalReceptionDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
							clinicalReceptionDateTimeStr);
					basicInfo.setClinicalReceptionDateTime(clinicalReceptionDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			basicInfo.setOutpatientOfDoctorName((String) hospitalVisitInfo.get("OUTPATIENTOFDOCTORNAME"));

			basicInfo.setResponsiblePersonName((String) hospitalVisitInfo.get("RESPONSIBLEPERSONNAME"));

			basicInfo.setInHospitalTypeCode((String) hospitalVisitInfo.get("INHOSPITALTYPECODE"));

			basicInfo.setInHospitalTypeName((String) hospitalVisitInfo.get("INHOSPITALTYPENAME"));

			basicInfo.setInHospitalStateCode((String) hospitalVisitInfo.get("INHOSPITALSTATECODE"));

			basicInfo.setInHospitalStateName((String) hospitalVisitInfo.get("INHOSPITALSTATENAME"));

			basicInfo.setAutopsyCode((String) hospitalVisitInfo.get("AUTOPSYCODE"));
			basicInfo.setAutopsyName((String) hospitalVisitInfo.get("AUTOPSYNAME"));

			HospitalVisitCureInfo cureInfo = new HospitalVisitCureInfo();
			cureInfo.setVisitGuid(visitGuid);
			BigDecimal rescueNumber = (BigDecimal) hospitalVisitInfo.get("RESCUENUMBER");
			if (rescueNumber != null) {
				cureInfo.setRescueNumber(rescueNumber.intValue());
			}

			BigDecimal rescueSucceedNumber = (BigDecimal) hospitalVisitInfo.get("RESCUESUCCEEDNUMBER");
			if (rescueSucceedNumber != null) {
				cureInfo.setRescueSucceedNumber(rescueSucceedNumber.intValue());
			}

			cureInfo.setBloodTypeCode((String) hospitalVisitInfo.get("BLOODTYPECODE"));
			cureInfo.setBloodTypeName((String) hospitalVisitInfo.get("BLOODTYPENAME"));
			cureInfo.setRhBloodTypeCode((String) hospitalVisitInfo.get("RHBLOODTYPECODE"));
			cureInfo.setRhBloodTypeName((String) hospitalVisitInfo.get("RHBLOODTYPENAME"));

			BigDecimal infusionTimes = (BigDecimal) hospitalVisitInfo.get("INFUSIONTIMES");
			if (infusionTimes != null) {
				cureInfo.setInfusionTimes(infusionTimes.intValue());
			}

			BigDecimal followUpClinicLimit = (BigDecimal) hospitalVisitInfo.get("FOLLOWUPCLINICLIMITCODE");
			if (followUpClinicLimit != null) {
				cureInfo.setFollowUpClinicLimitCode(followUpClinicLimit.intValue() + "");
			}

			cureInfo.setFollowUpClinicLimitName((String) hospitalVisitInfo.get("FOLLOWUPCLINICLIMITNAME"));

			cureInfo.setFollowUpClinicDayNumber((BigDecimal) hospitalVisitInfo.get("FOLLOWINTERVAL"));

			BigDecimal hbsAgeResultCode = (BigDecimal) hospitalVisitInfo.get("HBSAGERESULTCODE");
			if (hbsAgeResultCode != null) {
				cureInfo.setHbsAgeResultCode(hbsAgeResultCode.intValue() + "");
			}
			cureInfo.setHbsAgeResultName((String) hospitalVisitInfo.get("HBSAGERESULTNAME"));

			BigDecimal hcvAbResultCode = (BigDecimal) hospitalVisitInfo.get("HCVABRESULTCODE");
			if (hcvAbResultCode != null) {
				cureInfo.setHcvAbResultCode(hcvAbResultCode.intValue() + "");
			}
			cureInfo.setHcvAbResultName((String) hospitalVisitInfo.get("HCVABRESULTNAME"));

			BigDecimal hivAbResultCode = (BigDecimal) hospitalVisitInfo.get("HIVABRESULTCODE");
			if (hivAbResultCode != null) {
				cureInfo.setHivAbResultCode(hivAbResultCode.intValue() + "");
			}
			cureInfo.setHivAbResultName((String) hospitalVisitInfo.get("HIVABRESULTNAME"));

			List<HospitalVisitCureWorker> cureWorkers = new ArrayList<HospitalVisitCureWorker>();
			HospitalVisitCureWorker cureWorker1 = new HospitalVisitCureWorker();
			cureWorker1.setProfessionTitleName("科主任");
			cureWorker1.setMedicalWorkerName((String) hospitalVisitInfo.get("DIRECTOR"));
			cureWorkers.add(cureWorker1);
			HospitalVisitCureWorker cureWorker2 = new HospitalVisitCureWorker();
			cureWorker2.setProfessionTitleName("主治医师");
			cureWorker2.setMedicalWorkerName((String) hospitalVisitInfo.get("ATTENDING_DOCTOR"));
			cureWorkers.add(cureWorker2);

			HospitalVisitCureWorker cureWorker3 = new HospitalVisitCureWorker();
			cureWorker3.setProfessionTitleName("住院医师");
			cureWorker3.setMedicalWorkerName((String) hospitalVisitInfo.get("DOCTOR_IN_CHARGE"));
			cureWorkers.add(cureWorker3);
			cureInfo.setCureWorkers(cureWorkers);

			List<Map<String, Object>> hospitalVisitDiagCompareInfos = export305DataMapper
					.getHospitalVisit305DiagCompareInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());
			List<HospitalVisitDiagAccordRecord> diagAccordRecords = new ArrayList<HospitalVisitDiagAccordRecord>();
			for (Map<String, Object> hospitalVisitDiagCompareInfo : hospitalVisitDiagCompareInfos) {

				HospitalVisitDiagAccordRecord diagAccordRecord = new HospitalVisitDiagAccordRecord();
				diagAccordRecord.setDiagCompareCode((String) hospitalVisitDiagCompareInfo.get("DIAGCOMPARECODE"));
				diagAccordRecord.setDiagCompareName((String) hospitalVisitDiagCompareInfo.get("DIAGCOMPARENAME"));
				diagAccordRecord.setDiagAccordCode((String) hospitalVisitDiagCompareInfo.get("DIAGACCORDCODE"));
				diagAccordRecord.setDiagAccordName((String) hospitalVisitDiagCompareInfo.get("DIAGACCORDNAME"));
				diagAccordRecords.add(diagAccordRecord);
			}
			cureInfo.setDiagAccordRecords(diagAccordRecords);
			HospitalVisitNurseInfo nurseInfo = new HospitalVisitNurseInfo();
			nurseInfo.setVisitGuid(visitGuid);
			nurseInfo.setSickDayNumber((BigDecimal) hospitalVisitInfo.get("SICKDAYNUMBER"));
			nurseInfo.setCriticalDayNumber((BigDecimal) hospitalVisitInfo.get("CRITICALDAYNUMBER"));
			HospitalVisitIntensiveCareInfo intensiveCareInfo = new HospitalVisitIntensiveCareInfo();
			intensiveCareInfo.setVisitGuid(visitGuid);
			intensiveCareInfo.setIcuNurseDayNumber((BigDecimal) hospitalVisitInfo.get("ICUNURSEDAYNUMBER"));
			intensiveCareInfo.setCcuNurseDayNumber((BigDecimal) hospitalVisitInfo.get("CCUNURSEDAYNUMBER"));

			nurseInfo.setSpecialNurseDayNumber((BigDecimal) hospitalVisitInfo.get("SPECIALNURSEDAYNUMBER"));
			nurseInfo.setFirstLevelNurseDayNumber((BigDecimal) hospitalVisitInfo.get("FIRSTLEVELNURSEDAYNUMBER"));
			nurseInfo.setSecondLevelNurseDayNumber((BigDecimal) hospitalVisitInfo.get("SECONDLEVELNURSEDAYNUMBER"));

			HospitalVisitInfusionBloodInfo infusionBloodInfo = new HospitalVisitInfusionBloodInfo();
			BigDecimal infusionBloodTimes = (BigDecimal) hospitalVisitInfo.get("SECONDLEVELNURSEDAYNUMBER");
			if (infusionBloodTimes != null) {
				infusionBloodInfo.setInfusionBloodTimes(infusionBloodTimes.intValue());
			}
			infusionBloodInfo
					.setInfusionBloodTotalVolume((BigDecimal) hospitalVisitInfo.get("INFUSIONBLOODTOTALVOLUME"));

			BigDecimal infusionBloodReactTimes = (BigDecimal) hospitalVisitInfo.get("INFUSIONBLOODREACTTIMES");
			if (infusionBloodReactTimes != null) {
				infusionBloodInfo.setInfusionBloodReactTimes(infusionBloodReactTimes.intValue());
			}

			HospitalVisitPressureSoreInfo pressureSoreInfo = new HospitalVisitPressureSoreInfo();
			pressureSoreInfo.setPressureSoreTimes((BigDecimal) hospitalVisitInfo.get("PRESSURESORETIMES"));
			
			HospitalVisitCostInfo visitCostInfo = new HospitalVisitCostInfo();
			visitCostInfo.setTotalCost((BigDecimal) hospitalVisitInfo.get("TOTALCOST"));
			visitCostInfo.setActuallyCost((BigDecimal) hospitalVisitInfo.get("ACTUALLYCOST"));

			cureInfo.setMedicalRecordQualityCode((String) hospitalVisitInfo.get("MEDICALRECORDQUALITYCODE"));
			cureInfo.setMedicalRecordQualityName((String) hospitalVisitInfo.get("MEDICALRECORDQUALITYNAME"));

			basicInfo.setMajorUnitCode((String) hospitalVisitInfo.get("MAJORUNITCODE"));
			basicInfo.setMajorUnitName((String) hospitalVisitInfo.get("MAJORUNITNAME"));

			basicInfo.setTroopServiceCode((String) hospitalVisitInfo.get("TROOPSERVICECODE"));
			basicInfo.setTroopServiceName((String) hospitalVisitInfo.get("TROOPSERVICENAME"));

			BigDecimal medicalSystemCode = (BigDecimal) hospitalVisitInfo.get("MEDICALSYSTEMCODE");
			if (medicalSystemCode != null) {
				basicInfo.setMedicalSystemCode(medicalSystemCode.intValue() + "");
			}
			basicInfo.setMedicalSystemName((String) hospitalVisitInfo.get("MEDICALSYSTEMNAME"));
			basicInfo.setIdTypeName((String) hospitalVisitInfo.get("IDTYPENAME"));
			basicInfo.setIdTypeCode((String) hospitalVisitInfo.get("IDTYPECODE"));

			basicInfo.setCostTypeName((String) hospitalVisitInfo.get("COSTTYPENAME"));
			basicInfo.setCostTypeCode((String) hospitalVisitInfo.get("COSTTYPECODE"));

			BigDecimal jobStateCode = (BigDecimal) hospitalVisitInfo.get("JOBSTATECODE");
			if (jobStateCode != null) {
				basicInfo.setJobStateCode(jobStateCode.intValue() + "");
			}

			basicInfo.setJobStateName((String) hospitalVisitInfo.get("JOBSTATENAME"));

			List<Map<String, Object>> hospitalVisitDiagInfos = export305DataMapper
					.getHospitalVisit305DiagInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());

			HospitalVisitDiseaseDiagInfo diseaseDiagInfo = new HospitalVisitDiseaseDiagInfo();
			diseaseDiagInfo.setVisitGuid(visitGuid);
			List<HospitalVisitDiseaseDiagRecord> diseaseDiagRecords = new ArrayList<HospitalVisitDiseaseDiagRecord>();
			for (Map<String, Object> hospitalVisitDiagInfo : hospitalVisitDiagInfos) {

				HospitalVisitDiseaseDiagRecord diseaseDiagRecord = new HospitalVisitDiseaseDiagRecord();
				diseaseDiagRecord.setDiagTypeCode((String) hospitalVisitDiagInfo.get("DIAGTYPECODE"));
				diseaseDiagRecord.setDiagTypeName((String) hospitalVisitDiagInfo.get("DIAGTYPENAME"));
				diseaseDiagRecord.setDiseaseDiagCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
				diseaseDiagRecord.setDiseaseDiagName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
				String confirmedDateTimeStr = (String) hospitalVisitDiagInfo.get("CONFIRMEDDATETIME");
				if (confirmedDateTimeStr != null) {
					try {
						Date confirmedDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, confirmedDateTimeStr);
						diseaseDiagRecord.setConfirmedDateTime(confirmedDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				diseaseDiagRecord.setTreatResultCode((String) hospitalVisitDiagInfo.get("TREATRESULTCODE"));
				diseaseDiagRecord.setTreatResultName((String) hospitalVisitDiagInfo.get("TREATRESULTNAME"));
				BigDecimal diagSortIndex = (BigDecimal) hospitalVisitDiagInfo.get("DIAGSORTINDEX");
				if (diagSortIndex != null) {
					diseaseDiagRecord.setDiagSortIndex(diagSortIndex.intValue());
				}
				diseaseDiagRecord.setTreatDayNumber((BigDecimal) hospitalVisitDiagInfo.get("TREATDAYNUMBER"));
				diseaseDiagRecords.add(diseaseDiagRecord);
			}

			Collections.sort(diseaseDiagRecords, new HospitalVisitDiseaseDiagRecord.DiseaseDiagRecordComparator());

			diseaseDiagInfo.setDiseaseDiagRecords(diseaseDiagRecords);

			List<Map<String, Object>> hospitalVisitOperateInfos = export305DataMapper
					.getHospitalVisit305OperateInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());

			HospitalVisitOperateInfo operateInfo = new HospitalVisitOperateInfo();
			operateInfo.setVisitGuid(visitGuid);
			List<HospitalVisitOperateRecord> operateRecords = new ArrayList<HospitalVisitOperateRecord>();
			for (Map<String, Object> hospitalVisitOperateInfo : hospitalVisitOperateInfos) {

				HospitalVisitOperateRecord operateRecord = new HospitalVisitOperateRecord();
				operateRecord.setOperateCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
				operateRecord.setOperateName((String) hospitalVisitOperateInfo.get("OPERATENAME"));
				BigDecimal opsIndex = (BigDecimal) hospitalVisitOperateInfo.get("OPSINDEX");
				if (opsIndex != null) {
					operateRecord.setOperateSortIndex(opsIndex.intValue());
				}

				operateRecord.setIncisionLevelCode((String) hospitalVisitOperateInfo.get("INCISIONLEVELCODE"));
				operateRecord.setIncisionLevelName((String) hospitalVisitOperateInfo.get("INCISIONLEVELNAME"));
				operateRecord.setIncisionLevelCode((String) hospitalVisitOperateInfo.get("CICATRIZETYPECODE"));
				operateRecord.setIncisionLevelName((String) hospitalVisitOperateInfo.get("CICATRIZETYPENAME"));
				String operateDateStr = (String) hospitalVisitOperateInfo.get("OPERATEDATE");
				if (operateDateStr != null) {
					try {
						Date operateDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, operateDateStr);
						operateRecord.setOperateStartDate(operateDate);
						operateRecord.setOperateEndDate(operateDate);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				operateRecord.setAnaesthesiaTypeCode((String) hospitalVisitOperateInfo.get("ANAESTHESIATYPECODE"));
				operateRecord.setAnaesthesiaTypeName((String) hospitalVisitOperateInfo.get("ANAESTHESIATYPENAME"));
				List<HospitalVisitOperateWorker> operateWorkers = new ArrayList<HospitalVisitOperateWorker>();
				HospitalVisitOperateWorker operateWorker1 = new HospitalVisitOperateWorker();
				operateWorker1.setProfessionTitleName("手术医师");
				operateWorker1.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("OPERATOR"));
				operateWorkers.add(operateWorker1);

				HospitalVisitOperateWorker operateWorker2 = new HospitalVisitOperateWorker();
				operateWorker2.setProfessionTitleName("第一助手");
				operateWorker2.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("FIRST_ASSISTANT"));
				operateWorkers.add(operateWorker2);

				HospitalVisitOperateWorker operateWorker3 = new HospitalVisitOperateWorker();
				operateWorker3.setProfessionTitleName("第二助手");
				operateWorker3.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("SECOND_ASSISTANT"));
				operateWorkers.add(operateWorker3);

				HospitalVisitOperateWorker operateWorker4 = new HospitalVisitOperateWorker();
				operateWorker4.setProfessionTitleName("第一助手");
				operateWorker4.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("ANESTHESIA_DOCTOR"));
				operateWorkers.add(operateWorker4);
				operateRecord.setOperateWorkers(operateWorkers);
				operateRecords.add(operateRecord);
			}
			operateInfo.setOperateRecords(operateRecords);

			List<Map<String, Object>> hospitalVisitTransferDeptInfos = export305DataMapper
					.getHospitalVisit305TransferDeptInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitTransferDeptInfo transferDeptInfo = new HospitalVisitTransferDeptInfo();
			transferDeptInfo.setVisitGuid(visitGuid);
			List<HospitalVisitTransferDeptRecord> transferDeptRecords = new ArrayList<HospitalVisitTransferDeptRecord>();
			for (Map<String, Object> hospitalVisitTransferDeptInfo : hospitalVisitTransferDeptInfos) {

				HospitalVisitTransferDeptRecord transferDeptRecord = new HospitalVisitTransferDeptRecord();
				transferDeptRecord.setOutDeptCode((String) hospitalVisitTransferDeptInfo.get("OUTDEPTCODE"));
				transferDeptRecord.setOutDeptName((String) hospitalVisitTransferDeptInfo.get("OUTDEPTNAME"));

				transferDeptRecord.setInDeptCode((String) hospitalVisitTransferDeptInfo.get("INDEPTCODE"));
				transferDeptRecord.setInDeptName((String) hospitalVisitTransferDeptInfo.get("INDEPTNAME"));
				String transferDeptInDateTimeStr = (String) hospitalVisitTransferDeptInfo.get("TRANSFERDEPTINDATETIME");
				if (transferDeptInDateTimeStr != null) {
					if (transferDeptInDateTimeStr != null) {
						try {
							Date transferDeptInDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
									transferDeptInDateTimeStr);
							transferDeptRecord.setTransferDeptInDateTime(transferDeptInDateTime);
							transferDeptRecord.setTransferDeptDateTime(transferDeptInDateTime);
						} catch (ParseException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
				String transferDeptOutDateTimeStr = (String) hospitalVisitTransferDeptInfo
						.get("TRANSFERDEPTOUTDATETIME");
				if (transferDeptOutDateTimeStr != null) {
					try {
						Date transferDeptOutDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								transferDeptOutDateTimeStr);
						transferDeptRecord.setTransferDeptOutDateTime(transferDeptOutDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				transferDeptRecords.add(transferDeptRecord);
			}
			transferDeptInfo.setTransferDeptRecords(transferDeptRecords);
		
			List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();

		
			infusionBloodInfo.setInfusionBloodRecords(infusionBloodRecords);


			hospitalVisitFillInfo.put("basicInfo", basicInfo);
			hospitalVisitFillInfo.put("cureInfo", cureInfo);
			hospitalVisitFillInfo.put("diseaseDiagInfo", diseaseDiagInfo);
			hospitalVisitFillInfo.put("operateInfo", operateInfo);
			hospitalVisitFillInfo.put("transferDeptInfo", transferDeptInfo);
			hospitalVisitFillInfo.put("nurseInfo", nurseInfo);
			hospitalVisitFillInfo.put("intensiveCareInfo", intensiveCareInfo);
			hospitalVisitFillInfo.put("infusionBloodInfo", infusionBloodInfo);
			hospitalVisitFillInfo.put("pressureSoreInfo", pressureSoreInfo);
			/*
			 * hospitalVisitFillInfo.put("doctorAdviceTemporaryInfo",
			 * doctorAdviceTemporaryInfo);
			 * hospitalVisitFillInfo.put("examinationReportsInfo",
			 * examinationReportsInfo);
			 */

			hospitalVisitFillInfo.put("visitCostInfo", visitCostInfo);
			hospitalVisitFillInfos.add(hospitalVisitFillInfo);
		}
		return hospitalVisitFillInfos;
	}

	@TargetDataSource(name = "ds1")
	@Transactional
	@Override
	public void insertHospitalVisitRecords(List<Map<String, Object>> datas, User user) {
		// TODO Auto-generated method stub
		for (Map<String, Object> data : datas) {
			insertHospitalVisitRecord(data, user);
		}
	}

	public int insertHospitalVisitRecord(Map<String, Object> data, User user) {
		HospitalVisitBasicInfo basicInfo = (HospitalVisitBasicInfo) data.get("basicInfo");
		CitizensInfo patient = new CitizensInfo();
		String custGuid = StringUtil.getId();
		patient.setGuid(custGuid);
		patient.setName(basicInfo.getPatientName());
		
		List<Map<String, Object>> sexs = exportDataMapper.getSexIdsByName(basicInfo.getSexName());
		if (!sexs.isEmpty()) {
			patient.setSexId((Integer) sexs.get(0).get("id"));
		}

		patient.setBirthday(basicInfo.getBirthday());
		List<Map<String, Object>> idDocumentTypes = exportDataMapper
				.getIdDocumentTypeByCode(basicInfo.getIdDocumentTypeCode());
		if (!idDocumentTypes.isEmpty()) {
			patient.setIdType((Integer) idDocumentTypes.get(0).get("id"));
		}

		patient.setIdNumber(basicInfo.getIdNumber());
		patient.setStatus(1);
		patient.setCreateDate(new Date());
		patient.setUpdateDate(new Date());

		FirstLevelMedical firstLevelMedical = new FirstLevelMedical();
		firstLevelMedical.setCitizensGuid(patient.getGuid());
		List<Map<String, Object>> hospitals = exportDataMapper.getHospitalByCode(basicInfo.getHospitalCode());
		if (!hospitals.isEmpty()) {
			firstLevelMedical.setHospitalId((Integer) hospitals.get(0).get("id"));
			basicInfo.setHospitalName((String) hospitals.get(0).get("name"));
		}
		firstLevelMedical.setGuid(basicInfo.getVisitGuid());
		firstLevelMedical.setTreatmentSignId(1);
		firstLevelMedical.setTreatmentTypeId(1);
		firstLevelMedical.setCreateDate(new Date());
		firstLevelMedical.setUpdateDate(new Date());
		firstLevelMedical.setStatus(1);

		HospitalizationNote note = new HospitalizationNote();
		note.setFirstLevelMedicalGuid(firstLevelMedical.getGuid());

		note.setInHospitalDate(basicInfo.getInHospitalDateTime());
		
		note.setOutHospitalDate(basicInfo.getOutHospitalDateTime());
		
		note.setVisitNumber(basicInfo.getVisitNumber().intValue());

		List<Map<String, Object>> inMedicalOffices = exportDataMapper.getOfficesByOfficeCode(basicInfo.getInDeptCode());
		if (!inMedicalOffices.isEmpty()) {
			note.setInDeptId((Integer) inMedicalOffices.get(0).get("id"));
		}

		List<Map<String, Object>> outMedicalOffices = exportDataMapper
				.getOfficesByOfficeCode(basicInfo.getOutDeptCode());
		if (!outMedicalOffices.isEmpty()) {
			note.setOutDeptId((Integer) outMedicalOffices.get(0).get("id"));
		}

		note.setMrId(basicInfo.getMrId());
		note.setOnlyId(basicInfo.getOnlyId());
		int count = hospitalizationNoteMapper.getHospitalizationNoteCountByMrIdAndOnlyId(basicInfo.getMrId(),
				basicInfo.getVisitNumber().intValue());
		if (count > 0) {
			return 1;
		}
		patientMapper.insert(patient);
		firstLevelMedicalMapper.insert(firstLevelMedical);
		
		try {
		TreatmentTrace initTreatmentTrace = new TreatmentTrace();
		initTreatmentTrace.setTraceDate(new Date());
		initTreatmentTrace.setTraceTypeId(1);
		initTreatmentTrace.setTreatmentGuid(basicInfo.getVisitGuid());
		initTreatmentTrace.setUserId(user.getName());
		treatmentTraceMapper.insertSelective(initTreatmentTrace);
		initTreatmentTrace.setTraceTypeId(2);
		treatmentTraceMapper.insertSelective(initTreatmentTrace);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		List<Map<String, Object>> inHospitalTypes = exportDataMapper
				.getMysqlInHospitalTypeByCode(basicInfo.getInHospitalTypeCode());

		if (!inHospitalTypes.isEmpty()) {
			note.setInHospitalTypeId((Integer) inHospitalTypes.get(0).get("id"));
		}

		List<Map<String, Object>> outHospitalTypes = exportDataMapper
				.getOutHospitalTypeByCode(basicInfo.getOutHospitalTypeCode());

		if (!outHospitalTypes.isEmpty()) {
			note.setOutHospitalTypeId((Integer) outHospitalTypes.get(0).get("id"));
		}
		hospitalizationNoteMapper.insertSelective(note);
		String filePath = myConfig.getHospitalVisitJsonPath() + StringUtil.getLocalPath(basicInfo.getVisitGuid());
//		String versionFilePath = myConfig.getHospitalVisitJsonVersionPath()
//				+ StringUtil.getLocalPath(basicInfo.getVisitGuid());
		String versionFilePath = myConfig.getHospitalVisitJsonVersionPath()+basicInfo.getVisitGuid()+"/";
		String fileName = basicInfo.getVisitGuid() + ".json";
		//String versionFileName = basicInfo.getVisitGuid() + "-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date())
		//		+ ".json";
		String versionFileName =DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";
		data.put("userId", user.getLoginName());
		data.put("userName", user.getName());
		String jsonMapJson = JsonUtil.objectToJson(data);
		
		try {
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			try {
				hospNoteBasicJsonMapper.insert(jsonMapJson);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			HospNoteVersion hospNoteVersion = new HospNoteVersion();
			hospNoteVersion.setCreateTime(new Date());
			hospNoteVersion.setFirstGuid(basicInfo.getVisitGuid());
			hospNoteVersion.setFileName(versionFileName);
			hospNoteVersion.setOperator(user.getName());
			hospNoteVersionMapper.insert(hospNoteVersion);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return 0;
		
		
	}

	@SuppressWarnings("unchecked")
	public Map<String, Object> readLineFile(String filePath, String fileName) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();

		try {
			File destFile = new File(filePath, fileName);
			String jsonStr = null;
			if (destFile.exists()) {
				FileReader fr = new FileReader(destFile);
				BufferedReader br = new BufferedReader(fr);
				jsonStr = br.readLine();
				jsonMap = JsonUtil.jsonToPojo(jsonStr, Map.class);

			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return jsonMap;
	}
	
	@Override
	public PageInfo<List<Map<String,Object>>> getOracleMedicalPageHospitalVisit(PatVisitVO patVisitVO){
		
		PageHelper.startPage(patVisitVO.getPageNo(),patVisitVO.getPageSize());
		List<Map<String,Object>> hospitalVisits = export305DataMapper.queryHospitalVisit305InfoByOracle(patVisitVO.getStartDate(), patVisitVO.getEndDate(),patVisitVO.getMrId(),patVisitVO.getVisitNumber(),patVisitVO.getOutDeptCode());
		PageInfo<List<Map<String,Object>>> pageInfo = new PageInfo(hospitalVisits);
		return pageInfo;
	}
	

	@Override
	public List<Map<String, Object>> queryOracleMedicalHospitalVisit(String outHospitalStartDate,
			String outHospitalEndDate,String patientId,Integer visitNum,String outDeptCode) {
		// TODO Auto-generated method stub
		return export305DataMapper.queryHospitalVisit305InfoByOracle(outHospitalStartDate, outHospitalEndDate,patientId,visitNum,outDeptCode);
	}

	private Result getHospitalVisitFillInfoByOracle(String queryMrId, Integer queryVisitNumber) {
		
		List<Map<String, Object>> hospitalVisitInfos = export305DataMapper
				.getHospitalVisit305InfoByOracleByMrIdAndVisitNumber(queryMrId, queryVisitNumber);
		List<Map<String, Object>> hospitalVisitFillInfos = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> hospitalVisitInfo : hospitalVisitInfos) {
			Map<String, Object> hospitalVisitFillInfo = new HashMap<String, Object>();
			String visitGuid = StringUtil.getId();
			//[start] 设置病案首页基本数据
			HospitalVisitBasicInfo basicInfo = new HospitalVisitBasicInfo();
			basicInfo.setVisitGuid(visitGuid);
			basicInfo.setPatientName((String) hospitalVisitInfo.get("PATIENTNAME"));
			basicInfo.setSexCode((String) hospitalVisitInfo.get("SEXCODE"));
			basicInfo.setSexName((String) hospitalVisitInfo.get("SEXNAME"));
			String birthdayStr = StringUtil.meaningStr((String) hospitalVisitInfo.get("BIRTHDAY"));
			Date birthday = null;
			if (birthdayStr != null) {
				try {
					birthday = DateUtil.dateParse(birthdayStr);
					basicInfo.setBirthday(birthday);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			basicInfo.setMedicalPayTypeCode((String)hospitalVisitInfo.get("COSTTYPECODE"));
			basicInfo.setMedicalPayTypeName((String)hospitalVisitInfo.get("COSTTYPENAME"));
			
			//人员类型
			basicInfo.setPersonnelCategoryCode((String)hospitalVisitInfo.get("ARMEDSERVICESCODE"));
			basicInfo.setPersonnelCategoryName((String)hospitalVisitInfo.get("ARMEDSERVICESNAME"));
			
			basicInfo.setHospitalCode(hospitalCode);
			String nativePlace = "";
			
			String idNumber = (String) hospitalVisitInfo.get("IDNUMBER");
			String mrId = (String) hospitalVisitInfo.get("MRID");
			if (StringUtils.isNoneBlank(idNumber) && Validator.isIDCard(idNumber)) {
				basicInfo.setIdDocumentTypeCode(idDocumentTypeCode);
				basicInfo.setIdDocumentTypeName("身份证");
				basicInfo.setIdNumber((String) hospitalVisitInfo.get("IDNUMBER"));
				//籍贯
//				if (StringUtils.isBlank(nativePlace) && idNumber.length() > 6) {
//					nativePlace = idNumber.substring(0, 6);
//					basicInfo.setNativePlace(nativePlace);
//				}
			} else {
				//读取军人保障卡
				List<Map<String, Object>> irList = insuranceAccountsMapper.getInsuranceAccountsList(mrId);
				
				if (null != irList && irList.size() > 0) {
					Map<String, Object> irMap = irList.get(0);
					String INSURANCE_NO = (String)irMap.get("INSURANCE_NO");
					if (StringUtils.isNotBlank(INSURANCE_NO)) {
						basicInfo.setIdDocumentTypeCode(jr_idDocumentTypeCode);
						basicInfo.setIdDocumentTypeName("军人保障卡");
						basicInfo.setIdNumber(INSURANCE_NO);
						//籍贯
//						if (StringUtils.isBlank(nativePlace) && INSURANCE_NO.length() > 6) {
//							nativePlace = INSURANCE_NO.substring(0, 6);
//							basicInfo.setNativePlace(nativePlace);
//						}
					}
				}
			}
			//身份证号和军人保证卡都为空,籍贯的值就是出生地的值
//			if (StringUtils.isBlank(nativePlace)) {
//				basicInfo.setNativePlace((String) hospitalVisitInfo.get("BIRTHADDRESS"));
//			}
			
			//籍贯的值就是出生地
			basicInfo.setNativePlace((String) hospitalVisitInfo.get("BIRTHADDRESS"));
			basicInfo.setNationalityCode((String) hospitalVisitInfo.get("NATIONALITYCODE"));
			basicInfo.setNationalityName((String) hospitalVisitInfo.get("NATIONALITYNAME"));
			basicInfo.setNationCode((String) hospitalVisitInfo.get("NATIONCODE"));
			basicInfo.setNationName((String) hospitalVisitInfo.get("NATIONNAME"));
			basicInfo.setBirthAddressCode((String) hospitalVisitInfo.get("BIRTHADDRESSCODE"));
			basicInfo.setBirthAddress((String) hospitalVisitInfo.get("BIRTHADDRESS"));

			basicInfo.setMarriageCode((String) hospitalVisitInfo.get("MARRIAGECODE"));
			basicInfo.setMarriageName((String) hospitalVisitInfo.get("MARRIAGENAME"));

			basicInfo.setProfessionCode((String) hospitalVisitInfo.get("PROFESSIONCODE"));
			basicInfo.setProfessionName((String) hospitalVisitInfo.get("PROFESSIONNAME"));

			basicInfo.setPermanentAddress((String) hospitalVisitInfo.get("PERMANENTADDRESS"));
			basicInfo.setPermanentAddressPostCode((String) hospitalVisitInfo.get("PERMANENTADDRESSPOSTCODE"));

			basicInfo.setLinkManName((String) hospitalVisitInfo.get("LINKMANNAME"));
			basicInfo.setLinkManAddress((String) hospitalVisitInfo.get("LINKMANADDRESS"));

			basicInfo.setLinkManPhone((String) hospitalVisitInfo.get("LINKMANPHONE"));
			basicInfo.setLinkManRelativeRelationCode((String) hospitalVisitInfo.get("LINKMANRELATIVERELATIONCODE"));
			basicInfo.setLinkManRelativeRelationName((String) hospitalVisitInfo.get("LINKMANRELATIVERELATIONNAME"));

			basicInfo.setOnlyId((String) hospitalVisitInfo.get("ONLYID"));
			basicInfo.setMrId((String) hospitalVisitInfo.get("MRID"));
			BigDecimal visitNumber = (BigDecimal) hospitalVisitInfo.get("VISITNUMBER");
			if (visitNumber != null) {
				basicInfo.setVisitNumber(visitNumber);
			}
			
			

			String inHospitalDateTimeStr = StringUtil.meaningStr((String) hospitalVisitInfo.get("INHOSPITALNDATETIME"));
			Date inHospitalDateTime = null;
			if (inHospitalDateTimeStr != null) {
				try {
					inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_FORMATE, inHospitalDateTimeStr);
					//Date diagConfirmedDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, inHospitalDateTimeStr);
					basicInfo.setInHospitalDateTime(inHospitalDateTime);
					basicInfo.setDiagConfirmedDateTime(inHospitalDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				
				return new Result(false, "入院日期为空,请联系信息科!");
			}
			

			basicInfo.setInDeptCode((String) hospitalVisitInfo.get("INDEPTCODE"));
			basicInfo.setInDeptName((String) hospitalVisitInfo.get("INDEPTNAME"));
			basicInfo.setOutDeptCode((String) hospitalVisitInfo.get("OUTDEPTCODE"));
			basicInfo.setOutDeptName((String) hospitalVisitInfo.get("OUTDEPTNAME"));

			if(StringUtils.isBlank(basicInfo.getInDeptCode())) {
				return new Result(false, "入院科室为空,请联系信息科!");
			}
			
			if(StringUtils.isBlank(basicInfo.getOutDeptCode())) {
				return new Result(false, "出院科室为空,请联系信息科!");
			}
			
			String outHospitalDateTimeStr = StringUtil
					.meaningStr((String) hospitalVisitInfo.get("OUTHOSPITALDATETIME"));
			if (outHospitalDateTimeStr != null) {
				try {
					Date outHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_FORMATE, outHospitalDateTimeStr);
					basicInfo.setOutHospitalDateTime(outHospitalDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				return new Result(false, "出院日期为空,请联系信息科!");
			}
			
			
			if (inHospitalDateTime != null && birthday != null) {
				long diff = inHospitalDateTime.getTime() - birthday.getTime();
				BigDecimal ageDecimal = new BigDecimal((diff / (1000 * 60 * 60 * 24)) / 365);
				basicInfo.setAge(ageDecimal);

			}

			basicInfo.setOutHospitalTypeCode((String) hospitalVisitInfo.get("OUTHOSPITALTYPECODE"));
			basicInfo.setOutHospitalTypeName((String) hospitalVisitInfo.get("OUTHOSPITALTYPENAME"));

			basicInfo.setWorkUnitName((String) hospitalVisitInfo.get("WORKUNITNAME"));

			String clinicalReceptionDateTimeStr = StringUtil
					.meaningStr((String) hospitalVisitInfo.get("CLINICALRECEPTIONDATETIME"));
			if (clinicalReceptionDateTimeStr != null) {
				try {
					Date clinicalReceptionDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
							clinicalReceptionDateTimeStr);
					basicInfo.setClinicalReceptionDateTime(clinicalReceptionDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
			
			

			basicInfo.setOutpatientOfDoctorName((String) hospitalVisitInfo.get("OUTPATIENTOFDOCTORNAME"));

			basicInfo.setResponsiblePersonName((String) hospitalVisitInfo.get("RESPONSIBLEPERSONNAME"));

			basicInfo.setInHospitalTypeCode((String) hospitalVisitInfo.get("INHOSPITALTYPECODE"));

			basicInfo.setInHospitalTypeName((String) hospitalVisitInfo.get("INHOSPITALTYPENAME"));

			basicInfo.setInHospitalStateCode((String) hospitalVisitInfo.get("INHOSPITALSTATECODE"));

			basicInfo.setInHospitalStateName((String) hospitalVisitInfo.get("INHOSPITALSTATENAME"));
			if(hospitalVisitInfo.get("AUTOPSYCODE")!=null) {
				BigDecimal autoPsyCode = (BigDecimal) hospitalVisitInfo.get("AUTOPSYCODE");
				basicInfo.setAutopsyCode(autoPsyCode.toString());
			}else {
				basicInfo.setAutopsyCode(null);
			}
			//basicInfo.setAutopsyCode(hospitalVisitInfo.get("AUTOPSYCODE")==null?null:hospitalVisitInfo.get("AUTOPSYCODE").);
			basicInfo.setAutopsyName((String) hospitalVisitInfo.get("AUTOPSYNAME"));
			//basicInfo.setMilitaryTrainingInjuryCode(militaryTrainingInjuryCode);
			//[end]
			
			//[start] 设置病案首页治疗信息
			HospitalVisitCureInfo cureInfo = new HospitalVisitCureInfo();
			cureInfo.setVisitGuid(visitGuid);
			BigDecimal rescueNumber = (BigDecimal) hospitalVisitInfo.get("RESCUENUMBER");
			if (rescueNumber != null) {
				cureInfo.setRescueNumber(rescueNumber.intValue());
			}else{
				cureInfo.setRescueNumber(0);
			}

			BigDecimal rescueSucceedNumber = (BigDecimal) hospitalVisitInfo.get("RESCUESUCCEEDNUMBER");
			if (rescueSucceedNumber != null) {
				cureInfo.setRescueSucceedNumber(rescueSucceedNumber.intValue());
			}else{
				cureInfo.setRescueSucceedNumber(0);
			}

			cureInfo.setBloodTypeCode((String) hospitalVisitInfo.get("BLOODTYPECODE"));
			cureInfo.setBloodTypeName((String) hospitalVisitInfo.get("BLOODTYPENAME"));
			cureInfo.setRhBloodTypeCode((String) hospitalVisitInfo.get("RHBLOODTYPECODE"));
			cureInfo.setRhBloodTypeName((String) hospitalVisitInfo.get("RHBLOODTYPENAME"));
			
			
			Date qualityTime = (Date) hospitalVisitInfo.get("DATE_OF_CONTROL_QUALITY");
			if(qualityTime!=null){
					
					cureInfo.setQualityControlDateTime(qualityTime);
				
			}
			
			
			//输液次数
			BigDecimal infusionTimes = (BigDecimal) hospitalVisitInfo.get("INFUSIONTIMES");
			if (infusionTimes != null) {
				//cureInfo.setInfusionReTimes(infusionTimes.intValue());
				cureInfo.setInfusionReactTimes(infusionTimes.intValue());
			}

			BigDecimal followUpClinicLimit = (BigDecimal) hospitalVisitInfo.get("FOLLOWUPCLINICLIMITCODE");
			if (followUpClinicLimit != null) {
				cureInfo.setFollowUpClinicLimitCode(followUpClinicLimit.intValue() + "");
			}

			cureInfo.setFollowUpClinicLimitName((String) hospitalVisitInfo.get("FOLLOWUPCLINICLIMITNAME"));
			//随诊单位
			String followintervalunits = (String) hospitalVisitInfo.get("FOLLOWINTERVALUNITS");
			if(hospitalVisitInfo.get("FOLLOWINTERVAL")!=null){
				BigDecimal followInterval = (BigDecimal) hospitalVisitInfo.get("FOLLOWINTERVAL");
				if(StringUtils.isNotBlank(followintervalunits)){
					if("月".equals(followintervalunits)){
						followInterval=followInterval.multiply(new BigDecimal(30));
					}else if("年".equals(followintervalunits)){
						followInterval=followInterval.multiply(new BigDecimal(365));
					}
				}
				cureInfo.setFollowUpClinicDayNumber(followInterval);
			}
			//cureInfo.setFollowUpClinicDayNumber((BigDecimal) hospitalVisitInfo.get("FOLLOWINTERVAL"));

			BigDecimal hbsAgeResultCode = (BigDecimal) hospitalVisitInfo.get("HBSAGERESULTCODE");
			if (hbsAgeResultCode != null) {
				cureInfo.setHbsAgeResultCode(hbsAgeResultCode.intValue() + "");
			}
			cureInfo.setHbsAgeResultName((String) hospitalVisitInfo.get("HBSAGERESULTNAME"));

			BigDecimal hcvAbResultCode = (BigDecimal) hospitalVisitInfo.get("HCVABRESULTCODE");
			if (hcvAbResultCode != null) {
				cureInfo.setHcvAbResultCode(hcvAbResultCode.intValue() + "");
			}
			cureInfo.setHcvAbResultName((String) hospitalVisitInfo.get("HCVABRESULTNAME"));

			BigDecimal hivAbResultCode = (BigDecimal) hospitalVisitInfo.get("HIVABRESULTCODE");
			if (hivAbResultCode != null) {
				cureInfo.setHivAbResultCode(hivAbResultCode.intValue() + "");
			}
			cureInfo.setHivAbResultName((String) hospitalVisitInfo.get("HIVABRESULTNAME"));

			List<HospitalVisitCureWorker> cureWorkers = new ArrayList<HospitalVisitCureWorker>();
			HospitalVisitCureWorker cureWorker1 = new HospitalVisitCureWorker();
			cureWorker1.setProfessionTitleName("科主任");
			cureWorker1.setMedicalWorkerName((String) hospitalVisitInfo.get("DIRECTOR"));
			cureWorkers.add(cureWorker1);
			HospitalVisitCureWorker cureWorker2 = new HospitalVisitCureWorker();
			cureWorker2.setProfessionTitleName("主治医师");
			cureWorker2.setMedicalWorkerName((String) hospitalVisitInfo.get("ATTENDING_DOCTOR"));
			cureWorkers.add(cureWorker2);

			HospitalVisitCureWorker cureWorker3 = new HospitalVisitCureWorker();
			cureWorker3.setProfessionTitleName("住院医师");
			cureWorker3.setMedicalWorkerName((String) hospitalVisitInfo.get("DOCTOR_IN_CHARGE"));
			cureWorkers.add(cureWorker3);
			cureInfo.setCureWorkers(cureWorkers);
			
			HospitalVisitCureWorker cureWorker4 = new HospitalVisitCureWorker();
			cureWorker4.setProfessionTitleName("编码员");
			cureWorker4.setMedicalWorkerName((String) hospitalVisitInfo.get("CATALOGER"));
			cureWorkers.add(cureWorker4);
			cureInfo.setCureWorkers(cureWorkers);
			
			
			HospitalVisitCureWorker cureWorker5 = new HospitalVisitCureWorker();
			cureWorker5.setProfessionTitleName("质控医师");
			cureWorker5.setMedicalWorkerName((String) hospitalVisitInfo.get("DOCTOR_OF_CONTROL_QUALITY"));
			cureWorkers.add(cureWorker5);
			cureInfo.setCureWorkers(cureWorkers);
			
			
			HospitalVisitCureWorker cureWorker6 = new HospitalVisitCureWorker();
			cureWorker6.setProfessionTitleName("质控护士");
			cureWorker6.setMedicalWorkerName((String) hospitalVisitInfo.get("NURSE_OF_CONTROL_QUALITY"));
			cureWorkers.add(cureWorker6);
			cureInfo.setCureWorkers(cureWorkers);
			
			HospitalVisitCureWorker cureWorker7 = new HospitalVisitCureWorker();
			cureWorker7.setProfessionTitleName("主(副主)任医师");
			cureWorker7.setMedicalWorkerName((String) hospitalVisitInfo.get("CHIEFDOCTOR"));
			cureWorkers.add(cureWorker7);
			cureInfo.setCureWorkers(cureWorkers);

			List<Map<String, Object>> hospitalVisitDiagCompareInfos = export305DataMapper
					.getHospitalVisit305DiagCompareInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());
			List<HospitalVisitDiagAccordRecord> diagAccordRecords = new ArrayList<HospitalVisitDiagAccordRecord>();
			for (Map<String, Object> hospitalVisitDiagCompareInfo : hospitalVisitDiagCompareInfos) {

				HospitalVisitDiagAccordRecord diagAccordRecord = new HospitalVisitDiagAccordRecord();
				diagAccordRecord.setDiagCompareCode((String) hospitalVisitDiagCompareInfo.get("DIAGCOMPARECODE"));
				diagAccordRecord.setDiagCompareName((String) hospitalVisitDiagCompareInfo.get("DIAGCOMPARENAME"));
				diagAccordRecord.setDiagAccordCode((String) hospitalVisitDiagCompareInfo.get("DIAGACCORDCODE"));
				diagAccordRecord.setDiagAccordName((String) hospitalVisitDiagCompareInfo.get("DIAGACCORDNAME"));
				diagAccordRecords.add(diagAccordRecord);
			}
			cureInfo.setDiagAccordRecords(diagAccordRecords);
			//[end]
			
			//[start] 设置病案首页护理信息
			HospitalVisitNurseInfo nurseInfo = new HospitalVisitNurseInfo();
			nurseInfo.setVisitGuid(visitGuid);
			if(hospitalVisitInfo.get("SICKDAYNUMBER")!=null){
				nurseInfo.setSickDayNumber((BigDecimal) hospitalVisitInfo.get("SICKDAYNUMBER"));
			}else{
				nurseInfo.setSickDayNumber(new BigDecimal(0));
			}
			if(hospitalVisitInfo.get("CRITICALDAYNUMBER")!=null){
				nurseInfo.setCriticalDayNumber((BigDecimal) hospitalVisitInfo.get("CRITICALDAYNUMBER"));
			}else{
				nurseInfo.setCriticalDayNumber(new BigDecimal(0));
			}
			
			/*HospitalVisitIntensiveCareInfo intensiveCareInfo = new HospitalVisitIntensiveCareInfo();
			intensiveCareInfo.setVisitGuid(visitGuid);
			intensiveCareInfo.setIcuNurseDayNumber((BigDecimal) hospitalVisitInfo.get("ICUNURSEDAYNUMBER"));
			intensiveCareInfo.setCcuNurseDayNumber((BigDecimal) hospitalVisitInfo.get("CCUNURSEDAYNUMBER"));*/
			if(hospitalVisitInfo.get("SPECIALNURSEDAYNUMBER")!=null){
				
				nurseInfo.setSpecialNurseDayNumber((BigDecimal) hospitalVisitInfo.get("SPECIALNURSEDAYNUMBER"));
			}else{
				nurseInfo.setSpecialNurseDayNumber(new BigDecimal(0));
			}
			if(hospitalVisitInfo.get("FIRSTLEVELNURSEDAYNUMBER")!=null){
				
				nurseInfo.setFirstLevelNurseDayNumber((BigDecimal) hospitalVisitInfo.get("FIRSTLEVELNURSEDAYNUMBER"));
			}else{
				nurseInfo.setFirstLevelNurseDayNumber(new BigDecimal(0));
			}
			nurseInfo.setSecondLevelNurseDayNumber((BigDecimal) hospitalVisitInfo.get("SECONDLEVELNURSEDAYNUMBER"));
			//[end]
			
			//[start] 设置病案首页输血信息
			//输血记录
			HospitalVisitInfusionBloodInfo infusionBloodInfo = new HospitalVisitInfusionBloodInfo();
			BigDecimal infusionBloodTimes = (BigDecimal) hospitalVisitInfo.get("SECONDLEVELNURSEDAYNUMBER");
			if (infusionBloodTimes != null) {
				infusionBloodInfo.setInfusionBloodTimes(infusionBloodTimes.intValue());
			}
			infusionBloodInfo
					.setInfusionBloodTotalVolume((BigDecimal) hospitalVisitInfo.get("INFUSIONBLOODTOTALVOLUME"));

			BigDecimal infusionBloodReactTimes = (BigDecimal) hospitalVisitInfo.get("INFUSIONBLOODREACTTIMES");
			if (infusionBloodReactTimes != null) {
				infusionBloodInfo.setInfusionBloodReactTimes(infusionBloodReactTimes.intValue());
			}
			infusionBloodInfo.setVisitGuid(basicInfo.getVisitGuid());
			
			
			List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();
			if(basicInfo.getMrId()!=null && basicInfo.getInHospitalDateTime()!=null && basicInfo.getOutHospitalDateTime()!=null) {
				BloodTransfusionVO bloodTransfusionVO = new BloodTransfusionVO();
				bloodTransfusionVO.setId(basicInfo.getMrId());
				bloodTransfusionVO.setInHospitalTime(basicInfo.getInHospitalDateTime());
				bloodTransfusionVO.setOutHospitalTime(basicInfo.getOutHospitalDateTime());
				infusionBloodRecords = this.getBloodTransfusionList(bloodTransfusionVO);
			}
			
			infusionBloodInfo.setInfusionBloodRecords(infusionBloodRecords);
			//[end]
//			HospitalVisitPressureSoreInfo pressureSoreInfo = new HospitalVisitPressureSoreInfo();
//			pressureSoreInfo.setPressureSoreTimes((BigDecimal) hospitalVisitInfo.get("PRESSURESORETIMES"));
			//[start] 设置病案首页费用信息
			HospitalVisitCostInfo visitCostInfo = new HospitalVisitCostInfo();
			visitCostInfo.setTotalCost((BigDecimal) hospitalVisitInfo.get("TOTALCOST"));
			visitCostInfo.setActuallyCost((BigDecimal) hospitalVisitInfo.get("ACTUALLYCOST"));
			List<Map<String, Object>> hospitalVisitCostRecords = export305DataMapper
					.getHospitalVisit305CostInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());
			for (Map<String, Object> hospitalVisitCostRecord : hospitalVisitCostRecords) {
				String medicalCostTypeName = (String) hospitalVisitCostRecord.get("COSTTYPENAME");
				String medicalCostTypeCode = (String) hospitalVisitCostRecord.get("COSTTYPECODE");
				BigDecimal costMoney = (BigDecimal) hospitalVisitCostRecord.get("COSTNUMBER");
				HospitalVisitCostRecord costRecord = new HospitalVisitCostRecord();
				costRecord.setMedicalCostTypeCode(medicalCostTypeCode);
				costRecord.setMedicalCostTypeName(medicalCostTypeName);
				costRecord.setCostMoney(costMoney);
				visitCostInfo.getCostRecords().add(costRecord);
			}
			//[end]
			cureInfo.setMedicalRecordQualityCode((String) hospitalVisitInfo.get("MEDICALRECORDQUALITYCODE"));
			cureInfo.setMedicalRecordQualityName((String) hospitalVisitInfo.get("MEDICALRECORDQUALITYNAME"));

			basicInfo.setMajorUnitCode((String) hospitalVisitInfo.get("MAJORUNITCODE"));
			basicInfo.setMajorUnitName((String) hospitalVisitInfo.get("MAJORUNITNAME"));

			basicInfo.setTroopServiceCode((String) hospitalVisitInfo.get("TROOPSERVICECODE"));
			basicInfo.setTroopServiceName((String) hospitalVisitInfo.get("TROOPSERVICENAME"));

			BigDecimal medicalSystemCode = (BigDecimal) hospitalVisitInfo.get("MEDICALSYSTEMCODE");
			if (medicalSystemCode != null) {
				basicInfo.setMedicalSystemCode(medicalSystemCode.intValue() + "");
			}
			basicInfo.setMedicalSystemName((String) hospitalVisitInfo.get("MEDICALSYSTEMNAME"));
			basicInfo.setIdTypeName((String) hospitalVisitInfo.get("IDTYPENAME"));
			basicInfo.setIdTypeCode((String) hospitalVisitInfo.get("IDTYPECODE"));

			System.out.println(hospitalVisitInfo);
			basicInfo.setCostTypeName((String) hospitalVisitInfo.get("COSTTYPENAME"));
			basicInfo.setCostTypeCode((String) hospitalVisitInfo.get("COSTTYPECODE"));
			
			BigDecimal injureCode = (BigDecimal)hospitalVisitInfo.get("TRAINING_INJURY_INDICATOR");
			if(injureCode!=null){
				basicInfo.setMilitaryTrainingInjuryCode(injureCode.toString());
			}
			
			//basicInfo.setMilitaryTrainingInjuryCode((String) hospitalVisitInfo.get("TRAINING_INJURY_INDICATOR"));
			basicInfo.setMilitaryTrainingInjuryName((String) hospitalVisitInfo.get("TRAININGINJURENAME"));
			BigDecimal jobStateCode = (BigDecimal) hospitalVisitInfo.get("JOBSTATECODE");
			if (jobStateCode != null) {
				basicInfo.setJobStateCode(jobStateCode.intValue() + "");
			}

			basicInfo.setJobStateName((String) hospitalVisitInfo.get("JOBSTATENAME"));
			
			//[start] 设置病案首页疾病诊断
			List<Map<String, Object>> hospitalVisitDiagInfos = export305DataMapper
					.getHospitalVisit305DiagInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());

			HospitalVisitDiseaseDiagInfo diseaseDiagInfo = new HospitalVisitDiseaseDiagInfo();
			diseaseDiagInfo.setVisitGuid(visitGuid);
			List<HospitalVisitDiseaseDiagRecord> diseaseDiagRecords = new ArrayList<HospitalVisitDiseaseDiagRecord>();
			for (Map<String, Object> hospitalVisitDiagInfo : hospitalVisitDiagInfos) {

				HospitalVisitDiseaseDiagRecord diseaseDiagRecord = new HospitalVisitDiseaseDiagRecord();
				diseaseDiagRecord.setDiagTypeCode((String) hospitalVisitDiagInfo.get("DIAGTYPECODE"));
				diseaseDiagRecord.setDiagTypeName((String) hospitalVisitDiagInfo.get("DIAGTYPENAME"));
				diseaseDiagRecord.setDiseaseDiagOriginalDesc((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
				diseaseDiagRecord.setDiseaseDiagCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
				if(hospitalVisitDiagInfo.get("DISEASEDIAGNAME")!=null && hospitalVisitDiagInfo.get("DISEASEDIAGCODE")!=null){
					
					diseaseDiagRecord.setDiseaseDiagName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME")+"-"+(String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
				}else{
					diseaseDiagRecord.setDiseaseDiagName(null);
				}
				String confirmedDateTimeStr = (String) hospitalVisitDiagInfo.get("CONFIRMEDDATETIME");
				
				
				if (confirmedDateTimeStr != null) {
					try {
						Date confirmedDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, confirmedDateTimeStr);
						diseaseDiagRecord.setConfirmedDateTime(confirmedDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				diseaseDiagRecord.setTreatResultCode((String) hospitalVisitDiagInfo.get("TREATRESULTCODE"));
				diseaseDiagRecord.setTreatResultName((String) hospitalVisitDiagInfo.get("TREATRESULTNAME"));
				BigDecimal diagSortIndex = (BigDecimal) hospitalVisitDiagInfo.get("DIAGSORTINDEX");
				if (diagSortIndex != null) {
					diseaseDiagRecord.setDiagSortIndex(diagSortIndex.intValue());
				}
				
				if(hospitalVisitDiagInfo.get("DIAGTYPECODE")!=null){
					if(("3").equals((String)hospitalVisitDiagInfo.get("DIAGTYPECODE"))){
						basicInfo.setMainDiseaseName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
						basicInfo.setMainDiseaseCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
					}
					
					if(hospitalVisitDiagInfo.get("DIAGTYPECODE")!=null && diagSortIndex != null){
						if("A".equals((String)hospitalVisitDiagInfo.get("DIAGTYPECODE")) && diagSortIndex.intValue()==1) {
							basicInfo.setSecondDiseaseName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
							basicInfo.setSecondDiseaseCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
						}
					}
				}

				diseaseDiagRecord.setOperateMarkName((String) hospitalVisitDiagInfo.get("OPERATEMARKNAME"));
				BigDecimal operateMarkCode = (BigDecimal) hospitalVisitDiagInfo.get("OPERATEMARKCODE");
				if (operateMarkCode != null) {
					diseaseDiagRecord.setOperateMarkCode("" + operateMarkCode.intValue());
				}

				diseaseDiagRecord.setTreatDayNumber((BigDecimal) hospitalVisitDiagInfo.get("TREATDAYNUMBER"));
				diseaseDiagRecords.add(diseaseDiagRecord);
			}
			Collections.sort(diseaseDiagRecords, new HospitalVisitDiseaseDiagRecord.DiseaseDiagRecordComparator());

			diseaseDiagInfo.setDiseaseDiagRecords(diseaseDiagRecords);
			//[end]
			
			//[start] 设置病案首页手术信息
			List<Map<String, Object>> hospitalVisitOperateInfos = export305DataMapper
					.getHospitalVisit305OperateInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());

			HospitalVisitOperateInfo operateInfo = new HospitalVisitOperateInfo();
			operateInfo.setVisitGuid(visitGuid);
			List<HospitalVisitOperateRecord> operateRecords = new ArrayList<HospitalVisitOperateRecord>();
			for (Map<String, Object> hospitalVisitOperateInfo : hospitalVisitOperateInfos) {
				//{INCISIONLEVELNAME=Ⅰ, OPERATECODE=86.3 18, ANAESTHESIATYPECODE=A, OPERATEDATE=2017-11-29 00:00:00, ANESTHESIA_DOCTOR=刘文飞, MRID=D314998, FIRST_ASSISTANT=胡喜华, ANAESTHESIATYPENAME=局麻, OPERATOR=刘文飞, VISITNUMBER=1, OPERATENAME=脂肪瘤切除术, OPSINDEX=1, INCISIONLEVELCODE=1, CICATRIZETYPENAME=甲, CICATRIZETYPECODE=1}
				//[INCISIONLEVELNAME=Ⅰ, OPERATECODE=86.3 18, ANAESTHESIATYPECODE=A, OPERATEDATE=2017-11-29 00:00:00, ANESTHESIA_DOCTOR=刘文飞, MRID=D314998, FIRST_ASSISTANT=胡喜华, ANAESTHESIATYPENAME=局麻, OPERATOR=刘文飞, VISITNUMBER=1, OPERATENAME=脂肪瘤切除术, OPSINDEX=1, INCISIONLEVELCODE=1, CICATRIZETYPENAME=甲, CICATRIZETYPECODE=1]
					
				HospitalVisitOperateRecord operateRecord = new HospitalVisitOperateRecord();
				operateRecord.setOperateOriginalDesc((String) hospitalVisitOperateInfo.get("OPERATENAME"));
				operateRecord.setOperateCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
				operateRecord.setOperateName((String) hospitalVisitOperateInfo.get("OPERATENAME")+"-"+(String) hospitalVisitOperateInfo.get("OPERATECODE"));

				operateRecord.setIncisionLevelCode((String) hospitalVisitOperateInfo.get("INCISIONLEVELCODE"));
				operateRecord.setIncisionLevelName((String) hospitalVisitOperateInfo.get("INCISIONLEVELNAME"));
				operateRecord.setCicatrizeTypeCode((String) hospitalVisitOperateInfo.get("CICATRIZETYPECODE"));
				//operateRecord.setIncisionLevelName((String) hospitalVisitOperateInfo.get("CICATRIZETYPENAME"));
				operateRecord.setCicatrizeTypeName((String) hospitalVisitOperateInfo.get("CICATRIZETYPENAME"));
				BigDecimal operateSortIndex = (BigDecimal) hospitalVisitOperateInfo.get("OPSINDEX");
				if (operateSortIndex != null) {
					operateRecord.setOperateSortIndex(operateSortIndex.intValue());
					if(1==operateSortIndex.intValue()){
						basicInfo.setFirstOperationName((String) hospitalVisitOperateInfo.get("OPERATENAME"));
						basicInfo.setFirstOperationCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
					}else if(2==operateSortIndex.intValue()){
						basicInfo.setSecondOperationName((String) hospitalVisitOperateInfo.get("OPERATENAME"));
						basicInfo.setSecondOperationCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
					}
				}
				String operateDateStr = (String) hospitalVisitOperateInfo.get("OPERATEDATE");
				if (operateDateStr != null) {
					try {
						Date operateDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, operateDateStr);
						operateRecord.setOperateStartDate(operateDate);
						operateRecord.setOperateEndDate(operateDate);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				
//				if(operateSortIndex!=null && hospitalVisitOperateInfo.get("MRID")!=null && visitId!=null){
//					
//					List<Map<String,Object>> masterOperationList = export305DataMapper.getOperationMasterByPatientIdAndVisitNumberAndOprNo((String)hospitalVisitOperateInfo.get("MRID"), visitId.intValue(), operateSortIndex.intValue());
//					if(CollectionUtils.isNotEmpty(masterOperationList)){
//						Map<String,Object> operationMasterMap = masterOperationList.get(0);
//						String startDate = (String)operationMasterMap.get("OPERATESTARTDATE");
//						String endDate = (String)operationMasterMap.get("OPERATEENDDATE");
//						try {
//							operateRecord.setOperateStartDate( DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, startDate));
//							operateRecord.setOperateEndDate( DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, endDate));
//						} catch (Exception e) {
//							e.printStackTrace();
//						}
//						
//					}
//				}
				
				
				
				
				operateRecord.setAnaesthesiaTypeCode((String) hospitalVisitOperateInfo.get("ANAESTHESIATYPECODE"));
				operateRecord.setAnaesthesiaTypeName((String) hospitalVisitOperateInfo.get("ANAESTHESIATYPENAME"));
				List<HospitalVisitOperateWorker> operateWorkers = new ArrayList<HospitalVisitOperateWorker>();
				HospitalVisitOperateWorker operateWorker1 = new HospitalVisitOperateWorker();
				operateWorker1.setProfessionTitleName("手术医师");
				operateWorker1.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("OPERATOR"));
				operateWorkers.add(operateWorker1);

				HospitalVisitOperateWorker operateWorker2 = new HospitalVisitOperateWorker();
				operateWorker2.setProfessionTitleName("第一助手");
				operateWorker2.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("FIRST_ASSISTANT"));
				operateWorkers.add(operateWorker2);

				HospitalVisitOperateWorker operateWorker3 = new HospitalVisitOperateWorker();
				operateWorker3.setProfessionTitleName("第二助手");
				operateWorker3.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("SECOND_ASSISTANT"));
				operateWorkers.add(operateWorker3);

				HospitalVisitOperateWorker operateWorker4 = new HospitalVisitOperateWorker();
				operateWorker4.setProfessionTitleName("麻醉医师");
				operateWorker4.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("ANESTHESIA_DOCTOR"));
				operateWorkers.add(operateWorker4);
				operateRecord.setOperateWorkers(operateWorkers);
				operateRecords.add(operateRecord);
			}
			
			Collections.sort(operateRecords,new HospitalVisitOperateRecord());
			operateInfo.setOperateRecords(operateRecords);
			//[end]
			
			//[start] 设置病案首页转科信息
			List<Map<String, Object>> hospitalVisitTransferDeptInfos = export305DataMapper
					.getHospitalVisit305TransferDeptInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitTransferDeptInfo transferDeptInfo = new HospitalVisitTransferDeptInfo();
			transferDeptInfo.setVisitGuid(visitGuid);
			List<HospitalVisitTransferDeptRecord> transferDeptRecords = new ArrayList<HospitalVisitTransferDeptRecord>();
			for (Map<String, Object> hospitalVisitTransferDeptInfo : hospitalVisitTransferDeptInfos) {

				HospitalVisitTransferDeptRecord transferDeptRecord = new HospitalVisitTransferDeptRecord();
				transferDeptRecord.setOutDeptCode((String) hospitalVisitTransferDeptInfo.get("OUTDEPTCODE"));
				transferDeptRecord.setOutDeptName((String) hospitalVisitTransferDeptInfo.get("OUTDEPTNAME"));

				transferDeptRecord.setInDeptCode((String) hospitalVisitTransferDeptInfo.get("INDEPTCODE"));
				transferDeptRecord.setInDeptName((String) hospitalVisitTransferDeptInfo.get("INDEPTNAME"));
				String transferDeptInDateTimeStr = (String) hospitalVisitTransferDeptInfo.get("TRANSFERDEPTINDATETIME");
				if (transferDeptInDateTimeStr != null) {
					if (transferDeptInDateTimeStr != null) {
						try {
							Date transferDeptInDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
									transferDeptInDateTimeStr);
							transferDeptRecord.setTransferDeptInDateTime(transferDeptInDateTime);
							transferDeptRecord.setTransferDeptDateTime(transferDeptInDateTime);
						} catch (ParseException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
				String transferDeptOutDateTimeStr = (String) hospitalVisitTransferDeptInfo
						.get("TRANSFERDEPTOUTDATETIME");
				if (transferDeptOutDateTimeStr != null) {
					try {
						Date transferDeptOutDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								transferDeptOutDateTimeStr);
						transferDeptRecord.setTransferDeptOutDateTime(transferDeptOutDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				transferDeptRecords.add(transferDeptRecord);
			}
			transferDeptInfo.setTransferDeptRecords(transferDeptRecords);
			
			//[end]
			/*List<Map<String, Object>> hospitalVisitTransferBloodInfos = export305DataMapper
					.getHospitalVisit305TransferBloodInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());*/
			//List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();
			
		
		//	List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();

			//[start] 设置病案首页医嘱信息
			List<Map<String, Object>> hospitalVisitDoctorAdviceInfos = export305DataMapper
					.getHospitalVisit305DoctorAdviceTemporaryInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitDoctorAdviceTemporaryInfo doctorAdviceTemporaryInfo = new HospitalVisitDoctorAdviceTemporaryInfo();
			doctorAdviceTemporaryInfo.setVisitGuid(visitGuid);
			Map<String, HospitalVisitDoctorAdviceTemporaryRecord> doctorAdviceTemporaryRecordMap = new HashMap<String, HospitalVisitDoctorAdviceTemporaryRecord>();
			for (Map<String, Object> hospitalVisitDoctorAdviceInfo : hospitalVisitDoctorAdviceInfos) {
				String detpCode = (String) hospitalVisitDoctorAdviceInfo.get("DEPTCODE");
				HospitalVisitDoctorAdviceTemporaryRecord doctorAdviceTemporaryRecord = null;
				if (doctorAdviceTemporaryRecordMap.containsKey(detpCode)) {
					doctorAdviceTemporaryRecord = doctorAdviceTemporaryRecordMap.get(detpCode);
				} else {
					doctorAdviceTemporaryRecord = new HospitalVisitDoctorAdviceTemporaryRecord();
					doctorAdviceTemporaryRecord.setMrId(basicInfo.getMrId());
					doctorAdviceTemporaryRecord.setPatientName(basicInfo.getPatientName());
					doctorAdviceTemporaryRecord.setDeptName((String) hospitalVisitDoctorAdviceInfo.get("DEPT_NAME"));
					doctorAdviceTemporaryRecordMap.put(detpCode, doctorAdviceTemporaryRecord);
				}

				HospitalVisitDoctorAdviceTemporaryItem doctorAdviceTemporaryItem = new HospitalVisitDoctorAdviceTemporaryItem();

				String presupposeDateTimeStr = (String) hospitalVisitDoctorAdviceInfo.get("PRESUPPOSEDATETIME");
				if (presupposeDateTimeStr != null) {
					try {
						Date presupposeDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, presupposeDateTimeStr);
						doctorAdviceTemporaryItem.setPresupposeDateTime(presupposeDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

				StringBuilder sbDoctorAdviceContent = new StringBuilder();

				String orderText = (String) hospitalVisitDoctorAdviceInfo.get("ORDER_TEXT");
				if (orderText != null) {
					sbDoctorAdviceContent.append(orderText);
				}

				BigDecimal dosag = (BigDecimal) hospitalVisitDoctorAdviceInfo.get("DOSAGE");

				String dosagUnits = (String) hospitalVisitDoctorAdviceInfo.get("DOSAGE_UNITS");
				if (dosag != null && dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosag + dosagUnits);
				} else if (dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosagUnits);
				} else if (dosag != null) {
					sbDoctorAdviceContent.append("   " + dosag);
				}

				String administration = (String) hospitalVisitDoctorAdviceInfo.get("ADMINISTRATION");
				if (administration != null) {
					sbDoctorAdviceContent.append("   " + administration);
				}
				doctorAdviceTemporaryItem.setDoctorAdviceContent(sbDoctorAdviceContent.toString());
				doctorAdviceTemporaryItem.setDoctorName((String) hospitalVisitDoctorAdviceInfo.get("DOCTORNAME"));
				doctorAdviceTemporaryItem.setNurseName((String) hospitalVisitDoctorAdviceInfo.get("NURSENAME"));
				String executionDateTimeStr = (String) hospitalVisitDoctorAdviceInfo.get("EXECUTIONDATETIME");
				if (executionDateTimeStr != null) {
					try {
						Date executionDateTime = DateUtil.dateParse("HH:mm", executionDateTimeStr);
						doctorAdviceTemporaryItem.setExecutionDateTime(executionDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				doctorAdviceTemporaryRecord.getDoctorAdviceTemporaryItems().add(doctorAdviceTemporaryItem);
			}
			for (HospitalVisitDoctorAdviceTemporaryRecord hospitalVisitDoctorAdviceTemporaryRecord : doctorAdviceTemporaryRecordMap
					.values()) {
				doctorAdviceTemporaryInfo.getDoctorAdviceTemporaryRecords()
						.add(hospitalVisitDoctorAdviceTemporaryRecord);
			}

			List<Map<String, Object>> hospitalVisitDoctorAdviceStandingInfos = export305DataMapper
					.getHospitalVisit305DoctorAdviceStandingInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitDoctorAdviceStandingInfo doctorAdviceStandingInfo = new HospitalVisitDoctorAdviceStandingInfo();
			doctorAdviceStandingInfo.setVisitGuid(visitGuid);
			Map<String, HospitalVisitDoctorAdviceStandingRecord> doctorAdviceStandingRecordMap = new HashMap<String, HospitalVisitDoctorAdviceStandingRecord>();
			for (Map<String, Object> hospitalVisitDoctorAdviceStandingInfo : hospitalVisitDoctorAdviceStandingInfos) {

				String detpCode = (String) hospitalVisitDoctorAdviceStandingInfo.get("DEPTCODE");
				HospitalVisitDoctorAdviceStandingRecord doctorAdviceStandingRecord = null;
				if (doctorAdviceStandingRecordMap.containsKey(detpCode)) {
					doctorAdviceStandingRecord = doctorAdviceStandingRecordMap.get(detpCode);
				} else {
					doctorAdviceStandingRecord = new HospitalVisitDoctorAdviceStandingRecord();
					doctorAdviceStandingRecord.setMrId(basicInfo.getMrId());
					doctorAdviceStandingRecord.setPatientName(basicInfo.getPatientName());
					doctorAdviceStandingRecord.setDeptName((String) hospitalVisitDoctorAdviceStandingInfo.get("DEPT_NAME"));
					doctorAdviceStandingRecordMap.put(detpCode, doctorAdviceStandingRecord);
				}

				HospitalVisitDoctorAdviceStandingItem doctorAdviceStandingItem = new HospitalVisitDoctorAdviceStandingItem();

				String doctorAdviceStartDateTimeStr = (String) hospitalVisitDoctorAdviceStandingInfo
						.get("DOCTORADVICESTARTDATETIME");
				if (doctorAdviceStartDateTimeStr != null) {
					try {
						Date doctorAdviceStartDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								doctorAdviceStartDateTimeStr);
						doctorAdviceStandingItem.setDoctorAdviceStartDateTime(doctorAdviceStartDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

				StringBuilder sbDoctorAdviceContent = new StringBuilder();

				String orderText = (String) hospitalVisitDoctorAdviceStandingInfo.get("ORDER_TEXT");
				if (orderText != null) {
					sbDoctorAdviceContent.append(orderText);
				}

				BigDecimal dosag = (BigDecimal) hospitalVisitDoctorAdviceStandingInfo.get("DOSAGE");

				String dosagUnits = (String) hospitalVisitDoctorAdviceStandingInfo.get("DOSAGE_UNITS");
				if (dosag != null && dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosag + dosagUnits);
				} else if (dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosagUnits);
				} else if (dosag != null) {
					sbDoctorAdviceContent.append("   " + dosag);
				}

				String administration = (String) hospitalVisitDoctorAdviceStandingInfo.get("ADMINISTRATION");
				if (administration != null) {
					sbDoctorAdviceContent.append("   " + administration);
				}

				String frequency = (String) hospitalVisitDoctorAdviceStandingInfo.get("FREQUENCY");
				if (frequency != null) {
					sbDoctorAdviceContent.append("   " + frequency);
				}
				doctorAdviceStandingItem.setDoctorAdviceContent(sbDoctorAdviceContent.toString());
				doctorAdviceStandingItem.setDoctorAdviceStartDoctorName(
						(String) hospitalVisitDoctorAdviceStandingInfo.get("DOCTORADVICESTARTDOCTORNAME"));
				doctorAdviceStandingItem.setDoctorAdviceStartNurseName(
						(String) hospitalVisitDoctorAdviceStandingInfo.get("DOCTORADVICESTARTNURSENAME"));
				String doctorAdviceEndDateTimeStr = (String) hospitalVisitDoctorAdviceStandingInfo
						.get("DOCTORADVICEENDDATETIME");
				if (doctorAdviceEndDateTimeStr != null) {
					try {
						Date doctorAdviceEndDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								doctorAdviceEndDateTimeStr);
						doctorAdviceStandingItem.setDoctorAdviceEndDateTime(doctorAdviceEndDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				doctorAdviceStandingRecord.getDoctorAdviceStandingItems().add(doctorAdviceStandingItem);
			}

			for (HospitalVisitDoctorAdviceStandingRecord hospitalVisitDoctorAdviceStandingRecord : doctorAdviceStandingRecordMap
					.values()) {
				doctorAdviceStandingInfo.getDoctorAdviceStandingRecords().add(hospitalVisitDoctorAdviceStandingRecord);
			}
			//[end]
			/*List<Map<String, Object>> hospitalVisitExaminationReportInfos = export305DataMapper
					.getHospitalVisit305InspectionReportInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());*/
			
			//[start] 设置病案检验报告单信息
			HospitalVisitExaminationReportsInfo examinationReportsInfo = new HospitalVisitExaminationReportsInfo();
			examinationReportsInfo.setVisitGuid(visitGuid);
			try {
				examinationReportsInfo=getExaminationReportsInfo( hospitalVisitInfo,visitGuid);
			} catch (Exception e) {
				examinationReportsInfo=new HospitalVisitExaminationReportsInfo();
				examinationReportsInfo.setVisitGuid(visitGuid);
			}
			//[end]
			
			
			HospitalVisitRecordSheet hospitalVisitRecordSheet = new HospitalVisitRecordSheet();
			hospitalVisitRecordSheet = getHospitalVisitRecordSheet(hospitalVisitInfo,visitGuid);
			/*
			 * for (Map<String, Object> hospitalVisitExaminationReportInfo :
			 * hospitalVisitExaminationReportInfos) {
			 * 
			 * HospitalVisitExaminationReportsRecord examinationReportsRecord =
			 * new HospitalVisitExaminationReportsRecord(); String applyNo =
			 * (String)hospitalVisitExaminationReportInfo.get("APPLYNO");
			 * examinationReportsRecord.setPatientName((String)
			 * hospitalVisitExaminationReportInfo.get("PATIENTNAME"));
			 * examinationReportsRecord.setDeptCategoryName((String)
			 * hospitalVisitExaminationReportInfo.get("DEPTCATEGORYNAME"));
			 * examinationReportsRecord.setSexName((String)
			 * hospitalVisitExaminationReportInfo.get("SEXNAME"));
			 * examinationReportsRecord.setMrId(basicInfo.getMrId()); BigDecimal
			 * age =
			 * (BigDecimal)hospitalVisitExaminationReportInfo.get("AGENAME");
			 * if(age != null){
			 * examinationReportsRecord.setAgeName(age.intValue()+""); }
			 * examinationReportsRecord.setSpecimenTypeName((String)
			 * hospitalVisitExaminationReportInfo.get("SPECIMENTYPENAME"));
			 * examinationReportsRecord.setSubmittingPhysicianName((String)
			 * hospitalVisitExaminationReportInfo.get("SUBMITTINGPHYSICIANNAME")
			 * ); examinationReportsRecord.setClinicalDiagnosisName((String)
			 * hospitalVisitExaminationReportInfo.get("CLINICALDIAGNOSISNAME"));
			 * 
			 * String samplingDateTimeStr =
			 * (String)hospitalVisitExaminationReportInfo.get("SAMPLINGDATETIME"
			 * ); if(samplingDateTimeStr != null){ try { Date samplingDateTime =
			 * DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,samplingDateTimeStr
			 * );
			 * examinationReportsRecord.setSamplingDateTime(samplingDateTime); }
			 * catch (ParseException e) { // TODO Auto-generated catch block
			 * e.printStackTrace(); } }
			 * 
			 * String inspectDateTimeStr =
			 * (String)hospitalVisitExaminationReportInfo.get("INSPECTDATETIME")
			 * ; if(inspectDateTimeStr != null){ try { Date inspectDateTime =
			 * DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,inspectDateTimeStr)
			 * ; examinationReportsRecord.setInspectDateTime(inspectDateTime); }
			 * catch (ParseException e) { // TODO Auto-generated catch block
			 * e.printStackTrace(); } }
			 * examinationReportsRecord.setInspectionDoctorName((String)
			 * hospitalVisitExaminationReportInfo.get("INSPECTIONDOCTORNAME"));
			 * 
			 * String acceptanceCheckDateTimeStr =
			 * (String)hospitalVisitExaminationReportInfo.get(
			 * "ACCEPTANCECHECKDATETIME"); if(acceptanceCheckDateTimeStr !=
			 * null){ try { Date acceptanceCheckDateTime =
			 * DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
			 * acceptanceCheckDateTimeStr);
			 * examinationReportsRecord.setAcceptanceCheckDateTime(
			 * acceptanceCheckDateTime); } catch (ParseException e) { // TODO
			 * Auto-generated catch block e.printStackTrace(); } }
			 * 
			 * String reportDateTimeStr =
			 * (String)hospitalVisitExaminationReportInfo.get("REPORTDATETIME");
			 * if(reportDateTimeStr != null){ try { Date reportDateTime =
			 * DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,reportDateTimeStr);
			 * examinationReportsRecord.setReportDateTime(reportDateTime); }
			 * catch (ParseException e) { // TODO Auto-generated catch block
			 * e.printStackTrace(); } }
			 * examinationReportsRecord.setAuditorDoctorName((String)
			 * hospitalVisitExaminationReportInfo.get("AUDITORDOCTORNAME"));
			 * 
			 * examinationReportsInfo.getExaminationReportsRecords().add(
			 * examinationReportsRecord); List<Map<String, Object>>
			 * hospitalVisitExaminationItems =
			 * export305DataMapper.getHospitalVisit305InspectionItemInfoByOracle
			 * (applyNo); for (Map<String, Object> hospitalVisitExaminationItem
			 * : hospitalVisitExaminationItems) {
			 * 
			 * HospitalVisitExaminationReportsItem examinationReportsItem = new
			 * HospitalVisitExaminationReportsItem();
			 * examinationReportsItem.setProjectName((String)
			 * hospitalVisitExaminationItem.get("PROJECTNAME"));
			 * examinationReportsItem.setExaminationResult((String)
			 * hospitalVisitExaminationItem.get("INSPECTIONRESULT"));
			 * examinationReportsItem.setExaminationUnit((String)
			 * hospitalVisitExaminationItem.get("INSPECTIONUNIT"));
			 * examinationReportsItem.setExaminationResultMark((String)
			 * hospitalVisitExaminationItem.get("INSPECTIONRESULTMARK"));
			 * examinationReportsRecord.getExaminationReportsItems().add(
			 * examinationReportsItem); } }
			 */
			
			//病程记录
			HospitalVisitProgressNote progressNote = new HospitalVisitProgressNote();
			progressNote.setVisitGuid(visitGuid);
			List<String> fileNameList = Lists.newArrayList();
			String progressNoteFolder = StringUtil.ftpFolderGenerator((String)hospitalVisitInfo.get("MRID"),((BigDecimal)hospitalVisitInfo.get("VISITNUMBER")).intValue());
			
			String localProgressNoteFolder =myConfig.getProgressNoteDir()+visitGuid+"/";
			File progressNoteFile = new File(localProgressNoteFolder);
			if(!progressNoteFile.isDirectory()){
				progressNoteFile.mkdirs();
			}
			
			try {
				fileNameList = FtpClientUtil.downFile(myConfig.getFtpHost(),myConfig.getFtpPort(),myConfig.getFtpUsername(),myConfig.getFtpPassword(), progressNoteFolder, localProgressNoteFolder);
				System.out.println(fileNameList);
			} catch (Exception e) {
				fileNameList = Lists.newArrayList();
				log.error("提取病程记录出现问题:MRID="+(String)hospitalVisitInfo.get("MRID")+" 错误信息:"+e.getMessage());
			} 
			progressNote.setProgressList(fileNameList);
			
			//药物过敏
			HospitalVisitDrugAllergyInfo drugAllergyInfo = new  HospitalVisitDrugAllergyInfo();
			List<HospitalVisitDrugAllergyRecord> drugAllergyRecords = new ArrayList<HospitalVisitDrugAllergyRecord>();
			drugAllergyInfo.setVisitGuid(visitGuid);
			if(hospitalVisitInfo.get("ALERGYDYUGS")!=null){
				HospitalVisitDrugAllergyRecord drugAllergyRecord = new HospitalVisitDrugAllergyRecord();
				drugAllergyRecord.setDrugAllergyName((String)hospitalVisitInfo.get("ALERGYDYUGS"));
				drugAllergyRecords.add(drugAllergyRecord);
			}
			drugAllergyInfo.setDrugAllergyRecords(drugAllergyRecords);
			
			HospitalVisitInfectionInfo infectionInfo = new HospitalVisitInfectionInfo();
			infectionInfo.setVisitGuid(visitGuid);
			List<Map<String,Object>> infectionRecords = export305DataMapper.queryHospitalInspectionByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().toString());
			if(CollectionUtils.isEmpty(infectionRecords)){
				infectionInfo.setInfectionRecords(new ArrayList<HospitalVisitInfectionRecord>());
			}else{
			    List<HospitalVisitInfectionRecord> infectionRecordList = appendInfectionRecord(infectionRecords);
			    infectionInfo.setInfectionRecords(infectionRecordList);
			}
			
			
			hospitalVisitFillInfo.put("firstGuid", basicInfo.getVisitGuid());
			//基本信息
			hospitalVisitFillInfo.put("basicInfo", basicInfo);
			//治疗信息
			hospitalVisitFillInfo.put("cureInfo", cureInfo);
			//疾病信息
			hospitalVisitFillInfo.put("diseaseDiagInfo", diseaseDiagInfo);
			//手术信息
			hospitalVisitFillInfo.put("operateInfo", operateInfo);
			//转科记录
			hospitalVisitFillInfo.put("transferDeptInfo", transferDeptInfo);
			//护理信息(一级护理天数、....)
			hospitalVisitFillInfo.put("nurseInfo", nurseInfo);
			//hospitalVisitFillInfo.put("intensiveCareInfo", intensiveCareInfo);
			//输血记录
			hospitalVisitFillInfo.put("infusionBloodInfo", infusionBloodInfo);
//			hospitalVisitFillInfo.put("pressureSoreInfo", pressureSoreInfo);
			//临时医嘱
			hospitalVisitFillInfo.put("doctorAdviceTemporaryInfo", doctorAdviceTemporaryInfo);
			//长期医嘱
			hospitalVisitFillInfo.put("doctorAdviceStandingInfo", doctorAdviceStandingInfo);
			//检验报告单
			hospitalVisitFillInfo.put("examinationReportsInfo", examinationReportsInfo);
			//费用记录
			hospitalVisitFillInfo.put("visitCostInfo", visitCostInfo);
			//表单记录(心电图、生命体征单。。。)
			hospitalVisitFillInfo.put("recordSheet", hospitalVisitRecordSheet);
			//病程记录(表单)
			hospitalVisitFillInfo.put("progressNote", progressNote);
			//医院感染
			hospitalVisitFillInfo.put("infectionInfo", infectionInfo);
			
			hospitalVisitFillInfo.put("drugAllergyInfo", drugAllergyInfo);
			hospitalVisitFillInfos.add(hospitalVisitFillInfo);
		}
		return new Result(true, "查询成功", hospitalVisitFillInfos);
	}

	@TargetDataSource(name = "ds1")
	@Transactional(readOnly = true)
	@Override
	public int getHospitalizationNoteCountByMrIdAndOnlyId(String mrId, Integer visitNumber) {
		// TODO Auto-generated method stub
		return hospitalizationNoteMapper.getHospitalizationNoteCountByMrIdAndOnlyId(mrId, visitNumber);
	}

	@Transactional
	@Override
	public int synchronizDiseaseDiagInfo(List<Map<String, Object>> diseaseDiagRecords, String mrId,
			String visitNumber) {
		// TODO Auto-generated method stub
		int count= export305DataMapper.deleteDiseaseDiagRecordToOracle(mrId, visitNumber);
		System.out.println("---------------"+count+"-----------------");
		for (Map<String, Object> diseaseDiagRecord : diseaseDiagRecords) {
			HospitalVisitDiseaseDiagRecord diagRecord = new HospitalVisitDiseaseDiagRecord();
			diagRecord.setDiagTypeCode((String) diseaseDiagRecord.get("diagTypeCode"));
			diagRecord.setDiagSortIndex((Integer) diseaseDiagRecord.get("diagSortIndex"));
			String diseaseDiagName=((String) diseaseDiagRecord.get("diseaseDiagName")).split("-")[0];
			if(StringUtils.isEmpty(diseaseDiagName)){
				diagRecord.setDiseaseDiagOriginalDesc((String) diseaseDiagRecord.get("diseaseDiagOriginalDesc"));
			}else{
				
				diagRecord.setDiseaseDiagOriginalDesc(diseaseDiagName);
			}
			String confirmedDateTime = (String) diseaseDiagRecord.get("confirmedDateTime");
			if (confirmedDateTime != null) {
				try {
					diagRecord.setConfirmedDateTime(DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, confirmedDateTime));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			Object treatDayNumber = (Object) diseaseDiagRecord.get("treatDayNumber");

			if (treatDayNumber != null) {
				if (treatDayNumber instanceof Double) {
					diagRecord.setTreatDayNumber(new BigDecimal((Double) treatDayNumber));
				} else if (treatDayNumber instanceof Integer) {
					diagRecord.setTreatDayNumber(new BigDecimal((Integer) treatDayNumber));
				}

			}

			diagRecord.setTreatResultName((String) diseaseDiagRecord.get("treatResultName"));
			diagRecord.setOperateMarkCode((String) diseaseDiagRecord.get("operateMarkCode"));
			diagRecord.setDiseaseDiagCode((String) diseaseDiagRecord.get("diseaseDiagCode"));
			export305DataMapper.insertDiseaseDiagRecordToOracle(diagRecord, mrId, visitNumber);
		}

		return 0;
	}

	@Override
	public int synchronizOperateInfo(List<Map<String, Object>> operateRecords, String mrId, String visitNumber) {
		// TODO Auto-generated method stub
		export305DataMapper.deleteOperateRecordToOracle(mrId, visitNumber);
		for (Map<String, Object> operateRecordMap : operateRecords) {
			HospitalVisitOperateRecord operateRecord = new HospitalVisitOperateRecord();
			operateRecord.setOperateSortIndex((Integer) operateRecordMap.get("operateSortIndex"));

			String operateStartDate = (String) operateRecordMap.get("operateStartDate");
			if (operateStartDate != null) {
				try {
					operateRecord.setOperateStartDate(DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, operateStartDate));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			String operateEndDate = (String) operateRecordMap.get("operateEndDate");
			if (operateEndDate != null) {
				try {
					operateRecord.setOperateEndDate(DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, operateEndDate));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			//operateRecord.setOperateOriginalDesc((String) operateRecordMap.get("operateOriginalDesc"));
			operateRecord.setOperateOriginalDesc((String) operateRecordMap.get("operateName"));
			operateRecord.setOperateCode((String) operateRecordMap.get("operateCode"));
			operateRecord.setOperateName((String) operateRecordMap.get("operateName"));
			operateRecord.setCicatrizeTypeName((String) operateRecordMap.get("cicatrizeTypeName"));
			operateRecord.setIncisionLevelName((String) operateRecordMap.get("incisionLevelName"));
			operateRecord.setAnaesthesiaLevelName((String) operateRecordMap.get("anaesthesiaLevelName"));
			operateRecord.setAnaesthesiaTypeName((String) operateRecordMap.get("anaesthesiaTypeName"));
			List<Map<String, Object>> operateWorkers = (List<Map<String, Object>>) operateRecordMap
					.get("operateWorkers");
			String operaterName = null;
			String firstOpsAssistantName = null;
			String secondOpsAssistantName = null;
			String anaesthesiaOfDoctorName = null;
			for (Map<String, Object> operateWorker : operateWorkers) {
				if (((String) operateWorker.get("professionTitleName")).equals("手术医师")) {

					operaterName = (String) operateWorker.get("medicalWorkerName");
				} else if (((String) operateWorker.get("professionTitleName")).equals("第一助手")) {

					firstOpsAssistantName = (String) operateWorker.get("medicalWorkerName");
				} else if (((String) operateWorker.get("professionTitleName")).equals("第二助手")) {

					secondOpsAssistantName = (String) operateWorker.get("medicalWorkerName");
				} else if (((String) operateWorker.get("professionTitleName")).equals("麻醉医师")) {

					anaesthesiaOfDoctorName = (String) operateWorker.get("medicalWorkerName");
				}
			}
			export305DataMapper.insertOperateRecordToOracle(operateRecord, mrId, visitNumber, operaterName,
					firstOpsAssistantName, secondOpsAssistantName, anaesthesiaOfDoctorName);
			;

		}
		return 0;
	}
	
	
	public List<HospitalVisitInfectionRecord> appendInfectionRecord(List<Map<String,Object>> infectionMaps){
		List<HospitalVisitInfectionRecord> infectionRecordList = new ArrayList<>();
		if(CollectionUtils.isEmpty(infectionMaps)){
			return infectionRecordList;
		}
		////{CASEID=D305340(2), CONFIRMER=祝丙华, INFECTED_PART=抗菌药物使用, RID=INF1588229122661817240, INFECTED_TIME=2017-12-28, ISOPERINF=否, GROUPID=IG1588229122661817241, ISNOSOCOMIAL=院内, INFSTATE=排除, CONFIRMED_TIME=2018-01-03 13:28:19, VISITID=2, PATIENTID=D305340, INFECTED_DEPT=212304}, {BACTERIA=大肠埃希菌, CASEID=D305340(2), CONFIRMER=祝丙华, INFECTED_PART=下呼吸道, RID=INF1587504374809106790, INFECTED_TIME=2017-12-19, ISOPERINF=否, GROUPID=IG1587504374809106791, ISNOSOCOMIAL=院内, INFSTATE=排除, CONFIRMED_TIME=2018-01-03 13:28:19, VISITID=2, PATIENTID=D305340, INFECTED_DEPT=212304}]
		HospitalVisitInfectionRecord infectionRecord =null;
		for (Map<String,Object> infectionMap : infectionMaps) {
			infectionRecord = new HospitalVisitInfectionRecord();
			infectionRecord.setInfectDateTime(infectionMap.get("INFECTED_TIME")==null?null:(String)infectionMap.get("INFECTED_TIME"));
			infectionRecord.setBacteria(infectionMap.get("BACTERIA")==null?null:(String)infectionMap.get("BACTERIA"));
			infectionRecord.setConfirmedTime(infectionMap.get("CONFIRMED_TIME")==null?null:(String)infectionMap.get("CONFIRMED_TIME"));
			infectionRecord.setConfirmer(infectionMap.get("CONFIRMER")==null?null:(String)infectionMap.get("CONFIRMER"));
			infectionRecord.setInfectedDeptCode(infectionMap.get("INFECTED_DEPT")==null?null:(String)infectionMap.get("INFECTED_DEPT"));
			infectionRecord.setInfectedPart(infectionMap.get("INFECTED_PART")==null?null:(String)infectionMap.get("INFECTED_PART"));
			infectionRecord.setInfstate(infectionMap.get("INFSTATE")==null?null:(String)infectionMap.get("INFSTATE"));
			infectionRecord.setIsNoSocomial(infectionMap.get("ISNOSOCOMIAL")==null?null:(String)infectionMap.get("ISNOSOCOMIAL"));
			infectionRecord.setIsoperinf(infectionMap.get("ISOPERINF")==null?null:(String)infectionMap.get("ISOPERINF"));
			infectionRecord.setReportContent(infectionMap.get("REPORT_CONTENT")==null?null:(String)infectionMap.get("REPORT_CONTENT"));
			infectionRecord.setReportDoctor(infectionMap.get("REPORT_DOCTOR")==null?null:(String)infectionMap.get("REPORT_DOCTOR"));
			infectionRecord.setReportTime(infectionMap.get("REPORT_TIME")==null?null:(String)infectionMap.get("REPORT_TIME"));
			infectionRecordList.add(infectionRecord);
		}
		return infectionRecordList;
	}
	

	@Override
	public List<Map<String, Object>> queryOracleMedicalHospitalRecord(String mrId, Integer visitNumber) {
		return export305DataMapper.queryHospitalVisit305ScanInfoByOracle(mrId, visitNumber);
	}
	
	
	//获取护理记录信息
	public  HospitalVisitRecordSheet getHospitalVisitRecordSheet(Map<String, Object> hospitalVisitInfo,
			String firstGuid){
		HospitalVisitRecordSheet hospitalVisitRecordSheet = new HospitalVisitRecordSheet();
		String mrId=(String) hospitalVisitInfo.get("MRID");
		String visitNumber = ((BigDecimal) hospitalVisitInfo.get("VISITNUMBER")).toString();
/*		mrId="C121";
		visitNumber="23";*/
		String[] pdfFileSuffix=Const.PDF_FILE_SUFFIX;
		Map<String,Map<String,Object>> nurseRecordMap = new HashMap<>();
		
		for (String fileSuffix : pdfFileSuffix) {
			if("tiwen".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				/*try {
					

					map = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
					map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				} catch (IOException e) {
					map= new HashMap<>();
				}*/
				map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				hospitalVisitRecordSheet.setTemperatureRecord(map);
			}
			
			if("xuetcd".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				/*try {
					map = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					map= new HashMap<>();
				}*/
				map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				hospitalVisitRecordSheet.setBloodSugarRecord(map);
			}
			
			if("xindjc".equals(fileSuffix)){
				Map<String,Object> temperatureRecord= hospitalVisitRecordSheet.getTemperatureRecord();
				/*try {
					temperatureRecord = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					temperatureRecord= new HashMap<>();
				}*/
				temperatureRecord = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				hospitalVisitRecordSheet.setElectrocardiogramRecord(temperatureRecord);
			}
			
			if("smtzgc".equals(fileSuffix)){
				Map<String,Object> temperatureRecord= hospitalVisitRecordSheet.getTemperatureRecord();
				/*try {
					temperatureRecord = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					temperatureRecord= new HashMap<>();
				}*/
				temperatureRecord = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				hospitalVisitRecordSheet.setVitalSignRecord(temperatureRecord);
			}
			
			if("bingzhj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				/*try {
					map = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					map= new HashMap<>();
				}*/
				map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				nurseRecordMap.put("IllNurseRecord", map);
			}
			
			if("tebiehj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				/*try {
					map = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					map= new HashMap<>();
				}*/
				map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				nurseRecordMap.put("specialNurseRecord", map);
			}
			
			if("bingwhj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				/*try {
					map = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					map= new HashMap<>();
				}*/
				map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				nurseRecordMap.put("criticalCareRecord", map);
			}
			
			if("yibanhj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				/*try {
					map = PDFUtil.pdfRecordSheet(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				} catch (IOException e) {
					map= new HashMap<>();
				}*/
				map = getPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, visitNumber.toString(), firstGuid, fileSuffix);
				
				nurseRecordMap.put("generalNurseRecord", map);
			}
		}
		
		hospitalVisitRecordSheet.setNurseRecord(nurseRecordMap);
		return hospitalVisitRecordSheet;
	}
	
	//从新提取护理记录信息
	@Override
	public HospitalVisitRecordSheet getRepeactHospitalVisitRecordSheet(String firstGuid, String mrId, String visitNumber, String dateStr) {
		HospitalVisitRecordSheet hospitalVisitRecordSheet = new HospitalVisitRecordSheet();
		String[] pdfFileSuffix = Const.PDF_FILE_SUFFIX;
		Map<String,Map<String,Object>> nurseRecordMap = new HashMap<>();
		boolean flag = false;
		
		for (String fileSuffix : pdfFileSuffix) {
			//体温单
			if("tiwen".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					hospitalVisitRecordSheet.setTemperatureRecord((Map)result.getData());
					flag = true;
				} else {
					hospitalVisitRecordSheet.setTemperatureRecord(map);
				}
			}
			
			//血糖测定
			if("xuetcd".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId,
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					hospitalVisitRecordSheet.setBloodSugarRecord((Map)result.getData());
					flag = true;
				} else {
					hospitalVisitRecordSheet.setBloodSugarRecord(map);
				}
			}
			
			//心电检测
			if("xindjc".equals(fileSuffix)){
				Map<String,Object> temperatureRecord= hospitalVisitRecordSheet.getTemperatureRecord();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					hospitalVisitRecordSheet.setElectrocardiogramRecord((Map)result.getData());
					flag = true;
				} else {
					hospitalVisitRecordSheet.setElectrocardiogramRecord(temperatureRecord);
				}
				
			}
			
			//生命体征记录
			if("smtzgc".equals(fileSuffix)){
				Map<String,Object> temperatureRecord= hospitalVisitRecordSheet.getTemperatureRecord();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					hospitalVisitRecordSheet.setVitalSignRecord((Map)result.getData());
					flag = true;
				} else {
					hospitalVisitRecordSheet.setVitalSignRecord(temperatureRecord);
				}
				
			}
			
			//病重护理记录
			if("bingzhj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					nurseRecordMap.put("IllNurseRecord", (Map)result.getData());
					flag = true;
				} else {
					nurseRecordMap.put("IllNurseRecord", map);
				}
				
			}
			
			//特别护理记录
			if("tebiehj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					nurseRecordMap.put("specialNurseRecord", (Map)result.getData());
					flag = true;
				} else {
					nurseRecordMap.put("specialNurseRecord", map);
				}
				
			}
			
			//病危护理记录
			if("bingwhj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					nurseRecordMap.put("criticalCareRecord", (Map)result.getData());
					flag = true;
				} else {
					nurseRecordMap.put("criticalCareRecord", map);
				}
			}
			
			//一般护理记录
			if("yibanhj".equals(fileSuffix)){
				Map<String,Object> map= new HashMap<>();
				Result result = getRepeactPdfRecordSheetFormNurseSystem(myConfig.getCmisServerHost(), myConfig.getCmisFileLocalDir(), mrId, 
						visitNumber.toString(), firstGuid, fileSuffix, dateStr);
				
				if (result.isSuccess()) {
					nurseRecordMap.put("generalNurseRecord", (Map)result.getData());
					flag = true;
				} else {
					nurseRecordMap.put("generalNurseRecord", map);
				}
				
			}
		}
		
		hospitalVisitRecordSheet.setNurseRecord(nurseRecordMap);
		
		if (!flag) {
			return null;
		} 
		
		return hospitalVisitRecordSheet;
	}
	
	public Result getExaminationReportsStatus(Result result) {
		if (result.getStatus() == -1) {
			return new Result(false, "检验报告单服务器宕机了,请联系信息科");
		}
			
		if (result.getStatus() == 404) {
			return new Result(false, result.getMsg()+"不能访问报告单服务器,请联系信息科");
		}
		
		if (result.getStatus() == 500) {
			return new Result(false, "获取检验报告单异常信息如下:" + result.getMsg());
		}
		
		return new Result(true, "success", null, 200);
	}
	
	/**
	 * 获取检验报告单信息 支持重复提取
	 * @param hospitalVisitInfo
	 * @param firstGuid
	 * @return
	 */
	public Result getRepeatFetchExaminationReportsInfo(Map<String, Object> hospitalVisitInfo,
			String firstGuid, String destPath) {
		
		HospitalVisitExaminationReportsInfo hospitalVisitExaminationReportsInfo = new HospitalVisitExaminationReportsInfo();
		hospitalVisitExaminationReportsInfo.setVisitGuid(firstGuid);
		String mrId = MapUtils.getString(hospitalVisitInfo, "MRID");
		String inHospitalnDateTime = MapUtils.getString(hospitalVisitInfo, "INHOSPITALNDATETIME");
		String outHospitalDateTime = MapUtils.getString(hospitalVisitInfo, "OUTHOSPITALDATETIME");
		
		Map<String, String> params = new HashMap<>();
		params.put("soap_method", "GetIdsByMRN");
		params.put("mrn", mrId);
		params.put("startDate", inHospitalnDateTime);
		params.put("endDate", outHospitalDateTime);
		
		Result reportsResult = HttpClientUtil.doGet1(myConfig.getExaminationReportsServicePath(), params);
		//获取检验报告单调用情况
		if (!this.getExaminationReportsStatus(reportsResult).isSuccess()) {
			return this.getExaminationReportsStatus(reportsResult);
		}
			
		
		String resultJson = reportsResult.getData()!=""?(String)reportsResult.getData():"";

		List<String> fileList = new ArrayList<>();
		Result result = Analysis_Xml.getBasicDataIdList(resultJson);
		
		
		List<HospitalVisitExaminationReportsRecord> hospitalVisitExaminationReportsRecordList = Lists.newArrayList();
		
		if (result.isSuccess()) {
			List<Integer> reportIds = (List<Integer>) result.getData();
			if (CollectionUtils.isNotEmpty(reportIds)) {
				for (Integer reportId : reportIds) {

					String reportJson = null;
					try {
						params = new HashMap<>();
						params.put("soap_method", "GetReport");
						params.put("reportId", reportId + "");
						
						
						Result reportJsonResult = HttpClientUtil.doGet1(myConfig.getExaminationReportsServicePath(), params);
						if (!this.getExaminationReportsStatus(reportJsonResult).isSuccess()) {
							return this.getExaminationReportsStatus(reportJsonResult);
						}
						
						reportJson = (String)reportJsonResult.getData();
						
						if (StringUtils.isNotEmpty(reportJson)) {
							//D://publics/examination/xml/
							FileUtil.createOrEditFile(reportJson, destPath + "/", reportId + ".xml");
						}
						
						
						Result reportRootResult = Analysis_Xml.getCheckReportOrderDetailMsg(reportJson);
						
						if (!reportRootResult.isSuccess()) {
							log.error("-----解析检验报告单xml 信息失败----" + reportJson);
							return new Result(false, "-----解析检验报告单xml 信息失败----firstGuid=" + reportJson + "  " + reportJson);
						}
						
						if (null == Analysis_Xml.getCheckReportOrderDetailMsg(reportJson).getData()) {
							log.error("-----通过检验报告单的reportId查询不到数据--------firstGuid=" + firstGuid + " reportId=" + reportId);
							continue;
						}
						
						ReportRoot reportRoot = (ReportRoot) Analysis_Xml.getCheckReportOrderDetailMsg(reportJson).getData();

						HospitalVisitExaminationReportsRecord hospitalVisitExaminationReportsRecord = parseExamination(reportRoot);
						hospitalVisitExaminationReportsRecordList.add(hospitalVisitExaminationReportsRecord);
					} catch (Exception e) {
						log.error("------获取检验报告单异常-------firstGuid=" + firstGuid + " 异常信息如下:" +ExceptionUtil.getStackTrace(e));
						if (StringUtils.isNotEmpty(reportJson)) {
							try {
								FileUtil.createOrEditFile(reportJson, myConfig.getExaminationLocalDir() + firstGuid + "/error/", reportId + ".xml");
								continue;
							} catch (IOException e1) {
								e1.printStackTrace();
							}
						}
					}
				}
			}
		}
		hospitalVisitExaminationReportsInfo.setExaminationReportsRecords(hospitalVisitExaminationReportsRecordList);

		return new Result(true, "success", hospitalVisitExaminationReportsInfo, 200);
	}
	
	/**
	 * 获取检验报告单信息
	 * @param hospitalVisitInfo
	 * @param firstGuid
	 * @return
	 */
	public HospitalVisitExaminationReportsInfo getExaminationReportsInfo(Map<String, Object> hospitalVisitInfo,
			String firstGuid) {
		
		HospitalVisitExaminationReportsInfo hospitalVisitExaminationReportsInfo = new HospitalVisitExaminationReportsInfo();
		hospitalVisitExaminationReportsInfo.setVisitGuid(firstGuid);
		Map<String, String> params = new HashMap<>();
		String mrId = (hospitalVisitInfo.get("MRID") == null ? "" : (String)hospitalVisitInfo.get("MRID"));
		String inHospitalnDateTime =  (hospitalVisitInfo.get("INHOSPITALNDATETIME") == null ? ""
				: (String)hospitalVisitInfo.get("INHOSPITALNDATETIME"));
		String outHospitalDateTime = hospitalVisitInfo.get("OUTHOSPITALDATETIME") == null ? ""
				: (String) hospitalVisitInfo.get("OUTHOSPITALDATETIME");
		params.put("soap_method", "GetIdsByMRN");
		params.put("mrn", mrId);
		params.put("startDate", inHospitalnDateTime);
		params.put("endDate", outHospitalDateTime);

		String resultJson = HttpClientUtil.doGet(myConfig.getExaminationReportsServicePath(), params);

		List<String> fileList = new ArrayList<>();

		Result result = Analysis_Xml.getBasicDataIdList(resultJson);
		List<HospitalVisitExaminationReportsRecord> hospitalVisitExaminationReportsRecordList = Lists.newArrayList();
		
		if (result.isSuccess()) {
			List<Integer> reportIds = (List<Integer>) result.getData();
			if (CollectionUtils.isNotEmpty(reportIds)) {
				for (Integer reportId : reportIds) {

					String reportJson = null;
					try {
						params = new HashMap<>();
						params.put("soap_method", "GetReport");
						params.put("reportId", reportId + "");

						reportJson = HttpClientUtil.doGet(myConfig.getExaminationReportsServicePath(), params);
						if (StringUtils.isNotEmpty(reportJson)) {
							FileUtil.createOrEditFile(reportJson, myConfig.getExaminationLocalDir() + firstGuid + "/",
									reportId + ".xml");

						}
						ReportRoot reportRoot = (ReportRoot) Analysis_Xml.getCheckReportOrderDetailMsg(reportJson)
								.getData();

						HospitalVisitExaminationReportsRecord hospitalVisitExaminationReportsRecord = parseExamination(
								reportRoot);
						hospitalVisitExaminationReportsRecordList.add(hospitalVisitExaminationReportsRecord);

					} catch (Exception e) {
						if (StringUtils.isNotEmpty(reportJson)) {
							try {
								FileUtil.createOrEditFile(reportJson,
										myConfig.getExaminationLocalDir() + firstGuid + "/error/", reportId + ".xml");
								continue;
							} catch (IOException e1) {
								e1.printStackTrace();
							}

						}
					}

				}

			}

		}
		hospitalVisitExaminationReportsInfo.setExaminationReportsRecords(hospitalVisitExaminationReportsRecordList);

		return hospitalVisitExaminationReportsInfo;
	}

	/**
	 * 解析xml文件生成检验报告单记录
	 * @param reportRoot
	 * @return
	 * @throws ParseException
	 */
	public HospitalVisitExaminationReportsRecord parseExamination(ReportRoot reportRoot) throws ParseException {
		HospitalVisitExaminationReportsRecord hospitalVisitExaminationReportsRecord = new HospitalVisitExaminationReportsRecord();

		if (reportRoot != null) {
			Report report = reportRoot.getReport();
			hospitalVisitExaminationReportsRecord
					.setTitle(report.getTestsOrdered() == null ? "" : report.getTestsOrdered());
			hospitalVisitExaminationReportsRecord.setPatientName(report.getName() == null ? "" : report.getName());
			hospitalVisitExaminationReportsRecord.setAgeName(report.getAge() == null ? "" : report.getAge());
			hospitalVisitExaminationReportsRecord
					.setDeptCategoryName(report.getOrderDept() == null ? "" : report.getOrderDept());
			hospitalVisitExaminationReportsRecord
					.setSpecimenCode(report.getTestSN() == null ? "" : report.getTestSN());
			hospitalVisitExaminationReportsRecord.setSexName(report.getGender() == null ? "" : report.getGender());
			hospitalVisitExaminationReportsRecord.setBedName(report.getBedNo() == null ? "" : report.getBedNo());
			hospitalVisitExaminationReportsRecord.setBarCode(report.getBarcode() == null ? "" : report.getBarcode());
			hospitalVisitExaminationReportsRecord
					.setCostName(report.getChargeType() == null ? "" : report.getChargeType());
			hospitalVisitExaminationReportsRecord
					.setSpecimenTypeName(report.getSpecimen() == null ? "" : report.getSpecimen());
			hospitalVisitExaminationReportsRecord.setMrId(report.getMrn() == null ? "" : report.getMrn());
			hospitalVisitExaminationReportsRecord
					.setSubmittingPhysicianName(report.getOrderDoctor() == null ? "" : report.getOrderDoctor());
			hospitalVisitExaminationReportsRecord
					.setClinicalDiagnosisName(report.getDiagnosis() == null ? "" : report.getDiagnosis());
			hospitalVisitExaminationReportsRecord.setSamplingDateTime(
					report.getDtSample() == null ? null : DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", report.getDtSample()));
			hospitalVisitExaminationReportsRecord.setInspectDateTime(report.getDtAccept() == null ? null
					: DateUtil.dateParse("yyyy-MM-dd HH:mm",  report.getDtAccept()));
			hospitalVisitExaminationReportsRecord
					.setInspectionDoctorName(report.getTechTest() == null ? "" : report.getTechTest());
			hospitalVisitExaminationReportsRecord.setAcceptanceCheckDateTime(
					report.getDtAccept() == null ? null : DateUtil.dateParse("yyyy-MM-dd HH:mm", report.getDtAccept()));
			hospitalVisitExaminationReportsRecord.setReportDateTime(report.getDtValid() == null ? null
					: DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", report.getDtValid()));
			hospitalVisitExaminationReportsRecord
					.setAuditorDoctorName(report.getTechValid() == null ? "" : report.getTechValid());
			if (report != null) {
				List<ReportItem> reportItems = report.getReportItems();
				List<HospitalVisitExaminationReportsItem> hospitalVisitExaminationReportsItemList = Lists
						.newArrayList();
				HospitalVisitExaminationReportsItem hospitalVisitExaminationReportsItem = null;
				if (CollectionUtils.isNotEmpty(reportItems)) {
					for (ReportItem reportItem : reportItems) {
						hospitalVisitExaminationReportsItem = new HospitalVisitExaminationReportsItem();
						hospitalVisitExaminationReportsItem
								.setProjectName(reportItem.getName() == null ? "" : reportItem.getName());
						hospitalVisitExaminationReportsItem
								.setExaminationResult(reportItem.getResult() == null ? "" : reportItem.getResult());
						hospitalVisitExaminationReportsItem
								.setExaminationResultMark(reportItem.getFlag() == null ? "" : reportItem.getFlag());
						hospitalVisitExaminationReportsItem
								.setExaminationUnit(reportItem.getUnit() == null ? "" : reportItem.getUnit());
						hospitalVisitExaminationReportsItem
								.setReferenceValues(reportItem.getRefRange() == null ? "" : reportItem.getRefRange());
						hospitalVisitExaminationReportsItemList.add(hospitalVisitExaminationReportsItem);

					}
				}

				hospitalVisitExaminationReportsRecord
						.setExaminationReportsItems(hospitalVisitExaminationReportsItemList);
			}
		}
		return hospitalVisitExaminationReportsRecord;
	}

	@Override
	public int synchronizAllergyDrugsInfo(String allergyDrugs, String mrId, String visitNumber) {
		try {
			
		
		PatVisitKey patVisitKey = new PatVisitKey();
		patVisitKey.setPatientId(mrId);
		patVisitKey.setVisitId(new Short(visitNumber));
		PatVisit patVisit = patVisitMapper.selectByPrimaryKey(patVisitKey);
		if(patVisit!=null){
			patVisit.setAlergyDrugs(allergyDrugs);
			updatePatVisitByPatVisitKey(patVisit);
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return 0;
	}
	
	
	@Override
	public void synchronizNurseDaysInfo(Map<String,Object> nurseInfoMap, String mrId, String visitNumber) {
		try {
			
		if(nurseInfoMap!=null){
			PatVisitKey patVisitKey = new PatVisitKey();
			patVisitKey.setPatientId(mrId);
			patVisitKey.setVisitId(new Short(visitNumber));
			PatVisit patVisit = patVisitMapper.selectByPrimaryKey(patVisitKey);
			if(patVisit!=null){
				if(nurseInfoMap.get("criticalDayNumber")!=null){
					patVisit.setCriticalCondDays(((Integer)nurseInfoMap.get("criticalDayNumber")).shortValue());
				}
				if(nurseInfoMap.get("sickDayNumber")!=null){
					patVisit.setSeriousCondDays(((Integer)nurseInfoMap.get("sickDayNumber")).shortValue());
				}
				if(nurseInfoMap.get("specialNurseDayNumber")!=null){
					patVisit.setSpecLevelNursDays(((Integer)nurseInfoMap.get("specialNurseDayNumber")).shortValue());
				}
				if(nurseInfoMap.get("firstLevelNurseDayNumber")!=null){
					patVisit.setFirstLevelNursDays(((Integer)nurseInfoMap.get("firstLevelNurseDayNumber")).shortValue());
				}
				if(nurseInfoMap.get("secondLevelNurseDayNumber")!=null){
					patVisit.setSecondLevelNursDays(((Integer)nurseInfoMap.get("secondLevelNurseDayNumber")).shortValue());
				}
				if(nurseInfoMap.get("threeLevelNurseDayNumber")!=null){
					patVisit.setThirdLevelNursDays(((Integer)nurseInfoMap.get("threeLevelNurseDayNumber")).shortValue());
				}
				
				updatePatVisitByPatVisitKey(patVisit);
			}
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	@Override
	public void synchronizCrueInfo(Map<String, Object> crueInfoMap, String mrId, String visitNumber) {
	
		try {
			
		
		if(crueInfoMap!=null){
			PatVisitKey patVisitKey = new PatVisitKey();
			patVisitKey.setPatientId(mrId);
			patVisitKey.setVisitId(new Short(visitNumber));
			PatVisit patVisit = patVisitMapper.selectByPrimaryKey(patVisitKey);
			if(patVisit!=null){
				if(crueInfoMap.get("bloodTypeName")!=null){
					patVisit.setBloodType((String)crueInfoMap.get("bloodTypeName"));
				}else{
					patVisit.setBloodType(null);
				}
				
				if(crueInfoMap.get("rhBloodTypeCode")!=null){
					patVisit.setBloodTypeRh((String)crueInfoMap.get("rhBloodTypeCode"));
				}else{
					patVisit.setBloodTypeRh(null);
				}
				
				if(crueInfoMap.get("rescueNumber")!=null){
					patVisit.setEmerTreatTimes(((Integer)crueInfoMap.get("rescueNumber")).shortValue());
				}else{
					patVisit.setEmerTreatTimes(null);
				}
				
				if(crueInfoMap.get("rescueSucceedNumber")!=null){
					patVisit.setEscEmerTimes(((Integer)crueInfoMap.get("rescueSucceedNumber")).shortValue());
				}else{
					patVisit.setEscEmerTimes(null);
				}
				
				if(crueInfoMap.get("infusionReactTimes")!=null){
					patVisit.setInfusionReactTimes(((Integer)crueInfoMap.get("infusionReactTimes")).shortValue());
				}else{
					patVisit.setInfusionReactTimes(null);
				}
				
				if(crueInfoMap.get("followUpClinicLimitCode")!=null){
					patVisit.setFollowIndicator(new Short((String)crueInfoMap.get("followUpClinicLimitCode")));
				}
				
				if(crueInfoMap.get("followUpClinicDayNumber")!=null){
					Integer followUpClinicDays=(Integer) crueInfoMap.get("followUpClinicDayNumber");
					Integer followUpClinicDayNumber=null;
					if(followUpClinicDays>=365){
						followUpClinicDayNumber=followUpClinicDays/365;
					}else if(followUpClinicDays>=30 && followUpClinicDays<365){
						followUpClinicDayNumber=followUpClinicDays/30;
					}
					patVisit.setFollowInterval(followUpClinicDayNumber.shortValue());
				}
				if(crueInfoMap.get("hbsAgeResultCode")!=null){
					patVisit.setHbsagIndicator(new Short((String)crueInfoMap.get("hbsAgeResultCode")));
				}
				
				if(crueInfoMap.get("hcvAbResultCode")!=null){
					patVisit.setHcvAbIndicator(new Short((String)crueInfoMap.get("hcvAbResultCode")));
				}
				
				if(crueInfoMap.get("hivAbResultCode")!=null){
					patVisit.setHivAbIndicator(new Short((String)crueInfoMap.get("hivAbResultCode")));
				}
				if(crueInfoMap.get("cureWorkers")!=null){
					List<Map<String,Object>> cureWorkers = (List<Map<String, Object>>) crueInfoMap.get("cureWorkers");
					for (Map<String, Object> cureWorker : cureWorkers) {
						String professionTitleCode =(String) cureWorker.get("professionTitleCode");
						String medicalWorkerName=(String) cureWorker.get("medicalWorkerName");
						if("Y00".equals(professionTitleCode)){
							patVisit.setDirector(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y01".equals(professionTitleCode)){
							patVisit.setChiefDoctor(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y03".equals(professionTitleCode)){
							patVisit.setAttendingDoctor(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y04".equals(professionTitleCode)){
							patVisit.setAdvancedStudiesDoctor(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y05".equals(professionTitleCode)){
							patVisit.setPracticeDoctorOfGraduate(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y06".equals(professionTitleCode)){
							patVisit.setPracticeDoctor(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y07".equals(professionTitleCode)){
							patVisit.setCataloger(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y08".equals(professionTitleCode)){
							patVisit.setDoctorOfControlQuality(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y09".equals(professionTitleCode)){
							patVisit.setNurseOfControlQuality(medicalWorkerName==null?null:medicalWorkerName);
						}
						
						if("Y10".equals(professionTitleCode)){
							patVisit.setDoctorInCharge(medicalWorkerName==null?null:medicalWorkerName);
						}
					}
					
					if(crueInfoMap.get("medicalRecordQualityName")!=null){
						patVisit.setMrQuality((String)crueInfoMap.get("medicalRecordQualityName"));
					}
					
					if(crueInfoMap.get("qualityControlDateTime")!=null){
						//System.out.println((String)crueInfoMap.get("qualityControlDateTime"));
						patVisit.setCatalogDate(DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, (String)crueInfoMap.get("qualityControlDateTime")));
					}
						
					updatePatVisitByPatVisitKey(patVisit);
				}
				
			}
			
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//System.out.println(crueInfoMap);
		
	}
	
	
	@Transactional
	public int updatePatVisitByPatVisitKey(PatVisit patVisit){
		return patVisitMapper.updateByPrimaryKeySelective(patVisit);
	}

	@Override
	public List<HospitalVisitInfusionBloodRecord> getBloodTransfusionList(BloodTransfusionVO bloodTransfusionVO) {
		//创建数据库连接
		Connection connection = DBUtil.getConnection();
		PreparedStatement prepareStatement = null;
		ResultSet result = null;
		String sql = "select * from cfx where id =? and fxr >=? and fxr<=?";
		List<HospitalVisitInfusionBloodRecord> bloodList = new ArrayList<>();
		try {
			prepareStatement =	connection.prepareStatement(sql);
			prepareStatement.setString(1, bloodTransfusionVO.getId());
			prepareStatement.setDate(2, new java.sql.Date(bloodTransfusionVO.getInHospitalTime().getTime()));
			prepareStatement.setDate(3, new java.sql.Date(bloodTransfusionVO.getOutHospitalTime().getTime()));
			result = prepareStatement.executeQuery();
			HospitalVisitInfusionBloodRecord blood = null;
			while(result.next()) {
				blood = new HospitalVisitInfusionBloodRecord();
				blood.setDeptName(result.getString("kb"));
				Timestamp timestamp = result.getTimestamp("fxr");
				if (timestamp != null) {
					blood.setBleedingTime(new java.util.Date(timestamp.getTime()));
				}
				//blood.setBleedingTime(result.getDate("fxr"));
				blood.setPatientBloodType(result.getString("hxx"));
				blood.setPatientRhBloodType(result.getString("hrh"));
				blood.setBloodType(result.getString("lx"));
				blood.setBloodUnit(result.getString("dw"));
				blood.setBloodVolume(result.getString("xl"));
				blood.setOperator(result.getString("czr"));
				bloodList.add(blood);

			}
		} catch (SQLException e) {
			
			e.printStackTrace();
			return bloodList;
		} finally {
			DBUtil.close(connection, prepareStatement, result);
		}
		
		return bloodList;
		
		
	}

	
	@Override
	public Map<String, Object> getPdfRecordSheetFormNurseSystem(String url,String fileLocalDir,String patientId, String visitNumber, String visitGuid,String suffix){
		Map<String, Object> temperatureMap = null;
		String pdfRemoveurl = url+ patientId + "_" + visitNumber + "_"+ suffix+".pdf";
		String saveFileName = patientId + "_" + visitNumber + "_"+ suffix+".pdf";
		String saveFileParentPath = fileLocalDir+suffix+"/" + visitGuid;
		StringBuilder sbLog = null;
		try{
			
			int result = 500;
			try {
				result = PDFUtil.downLoadFileByFileUrl(pdfRemoveurl,saveFileName ,
						saveFileParentPath);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				if(sbLog == null){
					sbLog = new StringBuilder();
				}
				
				sbLog.append(String.format("获取%s,Url%s失败,%s", suffix,pdfRemoveurl,e.getMessage()));
				return new HashMap<>();
			}
			if(result == 200){
				temperatureMap = new HashMap<>();
				String pdfFilePath = saveFileParentPath + File.separator + saveFileName;
				temperatureMap.put("sourceFilePath",patientId + "_" + visitNumber +"_"+ suffix+".pdf");
				List<String> imagePathList = new ArrayList<String>();
				try {
					imagePathList = PDFUtil.getImageFormImage(pdfFilePath,
							fileLocalDir+suffix+"/" + visitGuid + "/");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					if(sbLog == null){
						sbLog = new StringBuilder();
					}
					sbLog.append(String.format("PDF%s,拆解图片集合错误%s", pdfFilePath,e.getMessage()));
					return new HashMap<>();
				}
				temperatureMap.put("imageFilePathList", imagePathList);
			}else{
				if(sbLog == null){
					sbLog = new StringBuilder();
				}
				if(404 == result){
					sbLog.append(String.format("%s,资源不存在", pdfRemoveurl));
				}else if(-1 == result){
					sbLog.append(String.format("%s无法连接服务器", pdfRemoveurl));
				}else{
					sbLog.append(String.format("%s,获取时内部错误", pdfRemoveurl));
				}
				return new HashMap<>();
			}
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			if(sbLog == null){
				sbLog = new StringBuilder();
			}
			sbLog.append(String.format("获取%s,Url%s失败,%s", suffix,pdfRemoveurl,e.getMessage()));
			return new HashMap<>();
		}finally{
			if(sbLog != null){
				ExceptionLog exceptionLog = new ExceptionLog();
				String logFileName =String.format("%s_%s_%s.log", patientId,visitNumber,suffix);
				exceptionLog.setLogFileName(logFileName);
				exceptionLog.setLogContent(sbLog.toString());
				logService.write(exceptionLog);
			}
		}
		
		
		return temperatureMap;

	}
	
	/**
	 * 重新提取护理记录
	 * @param url
	 * @param fileLocalDir  CMIS/bingwhj/firstGuid/firstGuid_时间/fileName
	 * @param patientId
	 * @param visitNumber
	 * @param visitGuid
	 * @param suffix
	 * @param suffix
	 * @return dateStr
	 */
	public Result getRepeactPdfRecordSheetFormNurseSystem(String url, String fileLocalDir, String patientId, 
			String visitNumber, String visitGuid,String suffix, String dateStr) {
		//url = "http://192.168.21.85:8090/upload/";
		Map<String, Object> temperatureMap = null;
		String pdfRemoteurl = url+ patientId + "_" + visitNumber + "_"+ suffix+".pdf";
		String saveFileName = patientId + "_" + visitNumber + "_"+ suffix+".pdf";
		String saveFileParentPath = fileLocalDir + suffix + File.separator + visitGuid + File.separator + visitGuid + "_" + dateStr;
		StringBuilder sbLog = null;
		
		try{
			int responseCode = 500;
			
			try {
				responseCode = PDFUtil.downLoadFileByFileUrl(pdfRemoteurl, saveFileName , saveFileParentPath);
			} catch (IOException e) {
				e.printStackTrace();
				if(sbLog == null){
					sbLog = new StringBuilder();
				}
				
				sbLog.append("获取" + suffix + " url=" + pdfRemoteurl + " " + ExceptionUtil.getStackTrace(e));
				
				return new Result(false, "获取" + suffix +"保存到本地失败", null, -1);
			}
			
			//pdf下载本地成功
			if(responseCode == 200) {
				temperatureMap = new HashMap<>();
				String pdfFilePath = saveFileParentPath + File.separator + saveFileName;
				temperatureMap.put("sourceFilePath", visitGuid + "_" + dateStr + File.separator + patientId + "_" + visitNumber +"_"+ suffix+".pdf");
				
				List<String> imagePathList = new ArrayList<String>();
				
				try {
					//pdf转换成图片
					imagePathList = PDFUtil.getImageFormImage(pdfFilePath, fileLocalDir + suffix+"/" + visitGuid + "/" + visitGuid + "_" + dateStr + File.separator, visitGuid + "_" + dateStr );
				} catch (IOException ioe) {
					ioe.printStackTrace();
					if(sbLog == null){
						sbLog = new StringBuilder();
					}
					sbLog.append(String.format("PDF%s,拆解图片集合错误%s", pdfFilePath, ExceptionUtil.getStackTrace(ioe)));
				}
				
				temperatureMap.put("imageFilePathList", imagePathList);
			} else {
				if(sbLog == null){
					sbLog = new StringBuilder();
				}
				
				if(404 == responseCode) {
					sbLog.append(String.format("%s,资源不存在", pdfRemoteurl));
					return new Result(false, pdfRemoteurl + "资源不存在", null, -3);
				} else if (-1 == responseCode) {
					sbLog.append(String.format("%s无法连接服务器", pdfRemoteurl));
					return new Result(false, pdfRemoteurl + "无法连接服务器", null, -4);
				} else {
					sbLog.append(String.format("%s,获取时内部错误", pdfRemoteurl));
					return new Result(false, pdfRemoteurl + "获取时内部错误", null, -5);
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
			if(sbLog == null){
				sbLog = new StringBuilder();
			}
			sbLog.append(String.format("获取%s,Url%s失败,%s", suffix,pdfRemoteurl,e.getMessage()));
			return new Result(false, "获取" + suffix + " Url" + pdfRemoteurl + "失败" + ExceptionUtil.getStackTrace(e));
		} finally {
			if(sbLog != null){
				try {
					File file  = new File(myConfig.getLogPath() + File.separator + "repeatFetch" + File.separator 
							+ visitGuid + File.separator + visitGuid + "_" + dateStr);
					if (!file.isDirectory()) {
						file.mkdirs();
					}
				} catch (Exception e2) {
				}
				
				//写入日志
				ExceptionLog exceptionLog = new ExceptionLog();
				String logFileName = String.format("%s_%s_%s_%s.log", dateStr, patientId, visitNumber, suffix);
				exceptionLog.setLogFileName(logFileName);
				exceptionLog.setLogContent(sbLog.toString());
				exceptionLog.setLogFilePath(myConfig.getLogPath() + File.separator + "repeatFetch" + File.separator 
						+ visitGuid + File.separator + visitGuid + "_" + dateStr);
				exceptionLog.writeLog();
			}
		}
		
		
		return new Result(true, "成功", temperatureMap, 200);
	}

	/**
	 * 为已有VisitGuid封装结构化首页
	 */
	@Override
	public Result getDatasByOracle(String mrId, Integer visitNumber, String visitGuid) {
		// TODO Auto-generated method stub
		return getHospitalVisitFillInfoByOracle(mrId, visitNumber, visitGuid);
	}

	private Result getHospitalVisitFillInfoByOracle(String queryMrId, Integer queryVisitNumber,String visitGuid) {
		
		List<Map<String, Object>> hospitalVisitInfos = export305DataMapper
				.getHospitalVisit305InfoByOracleByMrIdAndVisitNumber(queryMrId, queryVisitNumber);
		List<Map<String, Object>> hospitalVisitFillInfos = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> hospitalVisitInfo : hospitalVisitInfos) {
			Map<String, Object> hospitalVisitFillInfo = new HashMap<String, Object>();
			
			//[start] 设置病案首页基本数据
			HospitalVisitBasicInfo basicInfo = new HospitalVisitBasicInfo();
			basicInfo.setVisitGuid(visitGuid);
			basicInfo.setPatientName((String) hospitalVisitInfo.get("PATIENTNAME"));
			basicInfo.setSexCode((String) hospitalVisitInfo.get("SEXCODE"));
			basicInfo.setSexName((String) hospitalVisitInfo.get("SEXNAME"));
			String birthdayStr = StringUtil.meaningStr((String) hospitalVisitInfo.get("BIRTHDAY"));
			Date birthday = null;
			if (birthdayStr != null) {
				try {
					birthday = DateUtil.dateParse(birthdayStr);
					basicInfo.setBirthday(birthday);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			basicInfo.setMedicalPayTypeCode((String)hospitalVisitInfo.get("COSTTYPECODE"));
			basicInfo.setMedicalPayTypeName((String)hospitalVisitInfo.get("COSTTYPENAME"));
			
			//人员类型
			basicInfo.setPersonnelCategoryCode((String)hospitalVisitInfo.get("ARMEDSERVICESCODE"));
			basicInfo.setPersonnelCategoryName((String)hospitalVisitInfo.get("ARMEDSERVICESNAME"));
			
			basicInfo.setHospitalCode(hospitalCode);
			String nativePlace = "";
			
			String idNumber = (String) hospitalVisitInfo.get("IDNUMBER");
			String mrId = (String) hospitalVisitInfo.get("MRID");
			if (StringUtils.isNoneBlank(idNumber) && Validator.isIDCard(idNumber)) {
				basicInfo.setIdDocumentTypeCode(idDocumentTypeCode);
				basicInfo.setIdDocumentTypeName("身份证");
				basicInfo.setIdNumber((String) hospitalVisitInfo.get("IDNUMBER"));
				
			} else {
				//读取军人保障卡
				List<Map<String, Object>> irList = insuranceAccountsMapper.getInsuranceAccountsList(mrId);
				
				if (null != irList && irList.size() > 0) {
					Map<String, Object> irMap = irList.get(0);
					String INSURANCE_NO = (String)irMap.get("INSURANCE_NO");
					if (StringUtils.isNotBlank(INSURANCE_NO)) {
						basicInfo.setIdDocumentTypeCode(jr_idDocumentTypeCode);
						basicInfo.setIdDocumentTypeName("军人保障卡");
						basicInfo.setIdNumber(INSURANCE_NO);
						//籍贯
//						if (StringUtils.isBlank(nativePlace) && INSURANCE_NO.length() > 6) {
//							nativePlace = INSURANCE_NO.substring(0, 6);
//							basicInfo.setNativePlace(nativePlace);
//						}
					}
				}
			}
			
			
			//籍贯的值就是出生地
			basicInfo.setNativePlace((String) hospitalVisitInfo.get("BIRTHADDRESS"));
			basicInfo.setNationalityCode((String) hospitalVisitInfo.get("NATIONALITYCODE"));
			basicInfo.setNationalityName((String) hospitalVisitInfo.get("NATIONALITYNAME"));
			basicInfo.setNationCode((String) hospitalVisitInfo.get("NATIONCODE"));
			basicInfo.setNationName((String) hospitalVisitInfo.get("NATIONNAME"));
			basicInfo.setBirthAddressCode((String) hospitalVisitInfo.get("BIRTHADDRESSCODE"));
			basicInfo.setBirthAddress((String) hospitalVisitInfo.get("BIRTHADDRESS"));

			basicInfo.setMarriageCode((String) hospitalVisitInfo.get("MARRIAGECODE"));
			basicInfo.setMarriageName((String) hospitalVisitInfo.get("MARRIAGENAME"));

			basicInfo.setProfessionCode((String) hospitalVisitInfo.get("PROFESSIONCODE"));
			basicInfo.setProfessionName((String) hospitalVisitInfo.get("PROFESSIONNAME"));

			basicInfo.setPermanentAddress((String) hospitalVisitInfo.get("PERMANENTADDRESS"));
			basicInfo.setPermanentAddressPostCode((String) hospitalVisitInfo.get("PERMANENTADDRESSPOSTCODE"));

			basicInfo.setLinkManName((String) hospitalVisitInfo.get("LINKMANNAME"));
			basicInfo.setLinkManAddress((String) hospitalVisitInfo.get("LINKMANADDRESS"));

			basicInfo.setLinkManPhone((String) hospitalVisitInfo.get("LINKMANPHONE"));
			basicInfo.setLinkManRelativeRelationCode((String) hospitalVisitInfo.get("LINKMANRELATIVERELATIONCODE"));
			basicInfo.setLinkManRelativeRelationName((String) hospitalVisitInfo.get("LINKMANRELATIVERELATIONNAME"));

			basicInfo.setOnlyId((String) hospitalVisitInfo.get("ONLYID"));
			basicInfo.setMrId((String) hospitalVisitInfo.get("MRID"));
			BigDecimal visitNumber = (BigDecimal) hospitalVisitInfo.get("VISITNUMBER");
			if (visitNumber != null) {
				basicInfo.setVisitNumber(visitNumber);
			}
			
			

			String inHospitalDateTimeStr = StringUtil.meaningStr((String) hospitalVisitInfo.get("INHOSPITALNDATETIME"));
			Date inHospitalDateTime = null;
			if (inHospitalDateTimeStr != null) {
				try {
					inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_FORMATE, inHospitalDateTimeStr);
					//Date diagConfirmedDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, inHospitalDateTimeStr);
					basicInfo.setInHospitalDateTime(inHospitalDateTime);
					basicInfo.setDiagConfirmedDateTime(inHospitalDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				
				return new Result(false, "入院日期为空,请联系信息科!");
			}
			

			basicInfo.setInDeptCode((String) hospitalVisitInfo.get("INDEPTCODE"));
			basicInfo.setInDeptName((String) hospitalVisitInfo.get("INDEPTNAME"));
			basicInfo.setOutDeptCode((String) hospitalVisitInfo.get("OUTDEPTCODE"));
			basicInfo.setOutDeptName((String) hospitalVisitInfo.get("OUTDEPTNAME"));

			if(StringUtils.isBlank(basicInfo.getInDeptCode())) {
				return new Result(false, "入院科室为空,请联系信息科!");
			}
			
			if(StringUtils.isBlank(basicInfo.getOutDeptCode())) {
				return new Result(false, "出院科室为空,请联系信息科!");
			}
			
			String outHospitalDateTimeStr = StringUtil
					.meaningStr((String) hospitalVisitInfo.get("OUTHOSPITALDATETIME"));
			if (outHospitalDateTimeStr != null) {
				try {
					Date outHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_FORMATE, outHospitalDateTimeStr);
					basicInfo.setOutHospitalDateTime(outHospitalDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				return new Result(false, "出院日期为空,请联系信息科!");
			}
			
			
			if (inHospitalDateTime != null && birthday != null) {
				long diff = inHospitalDateTime.getTime() - birthday.getTime();
				BigDecimal ageDecimal = new BigDecimal((diff / (1000 * 60 * 60 * 24)) / 365);
				basicInfo.setAge(ageDecimal);

			}

			basicInfo.setOutHospitalTypeCode((String) hospitalVisitInfo.get("OUTHOSPITALTYPECODE"));
			basicInfo.setOutHospitalTypeName((String) hospitalVisitInfo.get("OUTHOSPITALTYPENAME"));

			basicInfo.setWorkUnitName((String) hospitalVisitInfo.get("WORKUNITNAME"));

			String clinicalReceptionDateTimeStr = StringUtil
					.meaningStr((String) hospitalVisitInfo.get("CLINICALRECEPTIONDATETIME"));
			if (clinicalReceptionDateTimeStr != null) {
				try {
					Date clinicalReceptionDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
							clinicalReceptionDateTimeStr);
					basicInfo.setClinicalReceptionDateTime(clinicalReceptionDateTime);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			basicInfo.setOutpatientOfDoctorName((String) hospitalVisitInfo.get("OUTPATIENTOFDOCTORNAME"));

			basicInfo.setResponsiblePersonName((String) hospitalVisitInfo.get("RESPONSIBLEPERSONNAME"));

			basicInfo.setInHospitalTypeCode((String) hospitalVisitInfo.get("INHOSPITALTYPECODE"));

			basicInfo.setInHospitalTypeName((String) hospitalVisitInfo.get("INHOSPITALTYPENAME"));

			basicInfo.setInHospitalStateCode((String) hospitalVisitInfo.get("INHOSPITALSTATECODE"));

			basicInfo.setInHospitalStateName((String) hospitalVisitInfo.get("INHOSPITALSTATENAME"));
			if(hospitalVisitInfo.get("AUTOPSYCODE")!=null) {
				BigDecimal autoPsyCode = (BigDecimal) hospitalVisitInfo.get("AUTOPSYCODE");
				basicInfo.setAutopsyCode(autoPsyCode.toString());
			}else {
				basicInfo.setAutopsyCode(null);
			}
			//basicInfo.setAutopsyCode(hospitalVisitInfo.get("AUTOPSYCODE")==null?null:hospitalVisitInfo.get("AUTOPSYCODE").);
			basicInfo.setAutopsyName((String) hospitalVisitInfo.get("AUTOPSYNAME"));
			//basicInfo.setMilitaryTrainingInjuryCode(militaryTrainingInjuryCode);
			//[end]
			
			//[start] 设置病案首页治疗信息
			HospitalVisitCureInfo cureInfo = new HospitalVisitCureInfo();
			cureInfo.setVisitGuid(visitGuid);
			BigDecimal rescueNumber = (BigDecimal) hospitalVisitInfo.get("RESCUENUMBER");
			if (rescueNumber != null) {
				cureInfo.setRescueNumber(rescueNumber.intValue());
			}else{
				cureInfo.setRescueNumber(0);
			}

			BigDecimal rescueSucceedNumber = (BigDecimal) hospitalVisitInfo.get("RESCUESUCCEEDNUMBER");
			if (rescueSucceedNumber != null) {
				cureInfo.setRescueSucceedNumber(rescueSucceedNumber.intValue());
			}else{
				cureInfo.setRescueSucceedNumber(0);
			}

			cureInfo.setBloodTypeCode((String) hospitalVisitInfo.get("BLOODTYPECODE"));
			cureInfo.setBloodTypeName((String) hospitalVisitInfo.get("BLOODTYPENAME"));
			cureInfo.setRhBloodTypeCode((String) hospitalVisitInfo.get("RHBLOODTYPECODE"));
			cureInfo.setRhBloodTypeName((String) hospitalVisitInfo.get("RHBLOODTYPENAME"));
			
			
			Date qualityTime = (Date) hospitalVisitInfo.get("DATE_OF_CONTROL_QUALITY");
			if(qualityTime!=null){
					
					cureInfo.setQualityControlDateTime(qualityTime);
				
			}
			
			
			//输液次数
			BigDecimal infusionTimes = (BigDecimal) hospitalVisitInfo.get("INFUSIONTIMES");
			if (infusionTimes != null) {
				//cureInfo.setInfusionReTimes(infusionTimes.intValue());
				cureInfo.setInfusionReactTimes(infusionTimes.intValue());
			}

			BigDecimal followUpClinicLimit = (BigDecimal) hospitalVisitInfo.get("FOLLOWUPCLINICLIMITCODE");
			if (followUpClinicLimit != null) {
				cureInfo.setFollowUpClinicLimitCode(followUpClinicLimit.intValue() + "");
			}

			cureInfo.setFollowUpClinicLimitName((String) hospitalVisitInfo.get("FOLLOWUPCLINICLIMITNAME"));
			//随诊单位
			String followintervalunits = (String) hospitalVisitInfo.get("FOLLOWINTERVALUNITS");
			if(hospitalVisitInfo.get("FOLLOWINTERVAL")!=null){
				BigDecimal followInterval = (BigDecimal) hospitalVisitInfo.get("FOLLOWINTERVAL");
				if(StringUtils.isNotBlank(followintervalunits)){
					if("月".equals(followintervalunits)){
						followInterval=followInterval.multiply(new BigDecimal(30));
					}else if("年".equals(followintervalunits)){
						followInterval=followInterval.multiply(new BigDecimal(365));
					}
				}
				cureInfo.setFollowUpClinicDayNumber(followInterval);
			}
			//cureInfo.setFollowUpClinicDayNumber((BigDecimal) hospitalVisitInfo.get("FOLLOWINTERVAL"));

			BigDecimal hbsAgeResultCode = (BigDecimal) hospitalVisitInfo.get("HBSAGERESULTCODE");
			if (hbsAgeResultCode != null) {
				cureInfo.setHbsAgeResultCode(hbsAgeResultCode.intValue() + "");
			}
			cureInfo.setHbsAgeResultName((String) hospitalVisitInfo.get("HBSAGERESULTNAME"));

			BigDecimal hcvAbResultCode = (BigDecimal) hospitalVisitInfo.get("HCVABRESULTCODE");
			if (hcvAbResultCode != null) {
				cureInfo.setHcvAbResultCode(hcvAbResultCode.intValue() + "");
			}
			cureInfo.setHcvAbResultName((String) hospitalVisitInfo.get("HCVABRESULTNAME"));

			BigDecimal hivAbResultCode = (BigDecimal) hospitalVisitInfo.get("HIVABRESULTCODE");
			if (hivAbResultCode != null) {
				cureInfo.setHivAbResultCode(hivAbResultCode.intValue() + "");
			}
			cureInfo.setHivAbResultName((String) hospitalVisitInfo.get("HIVABRESULTNAME"));

			List<HospitalVisitCureWorker> cureWorkers = new ArrayList<HospitalVisitCureWorker>();
			HospitalVisitCureWorker cureWorker1 = new HospitalVisitCureWorker();
			cureWorker1.setProfessionTitleName("科主任");
			cureWorker1.setMedicalWorkerName((String) hospitalVisitInfo.get("DIRECTOR"));
			cureWorkers.add(cureWorker1);
			HospitalVisitCureWorker cureWorker2 = new HospitalVisitCureWorker();
			cureWorker2.setProfessionTitleName("主治医师");
			cureWorker2.setMedicalWorkerName((String) hospitalVisitInfo.get("ATTENDING_DOCTOR"));
			cureWorkers.add(cureWorker2);

			HospitalVisitCureWorker cureWorker3 = new HospitalVisitCureWorker();
			cureWorker3.setProfessionTitleName("住院医师");
			cureWorker3.setMedicalWorkerName((String) hospitalVisitInfo.get("DOCTOR_IN_CHARGE"));
			cureWorkers.add(cureWorker3);
			cureInfo.setCureWorkers(cureWorkers);
			
			HospitalVisitCureWorker cureWorker4 = new HospitalVisitCureWorker();
			cureWorker4.setProfessionTitleName("编码员");
			cureWorker4.setMedicalWorkerName((String) hospitalVisitInfo.get("CATALOGER"));
			cureWorkers.add(cureWorker4);
			cureInfo.setCureWorkers(cureWorkers);
			
			
			HospitalVisitCureWorker cureWorker5 = new HospitalVisitCureWorker();
			cureWorker5.setProfessionTitleName("质控医师");
			cureWorker5.setMedicalWorkerName((String) hospitalVisitInfo.get("DOCTOR_OF_CONTROL_QUALITY"));
			cureWorkers.add(cureWorker5);
			cureInfo.setCureWorkers(cureWorkers);
			
			
			HospitalVisitCureWorker cureWorker6 = new HospitalVisitCureWorker();
			cureWorker6.setProfessionTitleName("质控护士");
			cureWorker6.setMedicalWorkerName((String) hospitalVisitInfo.get("NURSE_OF_CONTROL_QUALITY"));
			cureWorkers.add(cureWorker6);
			cureInfo.setCureWorkers(cureWorkers);
			
			HospitalVisitCureWorker cureWorker7 = new HospitalVisitCureWorker();
			cureWorker7.setProfessionTitleName("主(副主)任医师");
			cureWorker7.setMedicalWorkerName((String) hospitalVisitInfo.get("CHIEFDOCTOR"));
			cureWorkers.add(cureWorker7);
			cureInfo.setCureWorkers(cureWorkers);

			List<Map<String, Object>> hospitalVisitDiagCompareInfos = export305DataMapper
					.getHospitalVisit305DiagCompareInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());
			List<HospitalVisitDiagAccordRecord> diagAccordRecords = new ArrayList<HospitalVisitDiagAccordRecord>();
			for (Map<String, Object> hospitalVisitDiagCompareInfo : hospitalVisitDiagCompareInfos) {

				HospitalVisitDiagAccordRecord diagAccordRecord = new HospitalVisitDiagAccordRecord();
				diagAccordRecord.setDiagCompareCode((String) hospitalVisitDiagCompareInfo.get("DIAGCOMPARECODE"));
				diagAccordRecord.setDiagCompareName((String) hospitalVisitDiagCompareInfo.get("DIAGCOMPARENAME"));
				diagAccordRecord.setDiagAccordCode((String) hospitalVisitDiagCompareInfo.get("DIAGACCORDCODE"));
				diagAccordRecord.setDiagAccordName((String) hospitalVisitDiagCompareInfo.get("DIAGACCORDNAME"));
				diagAccordRecords.add(diagAccordRecord);
			}
			cureInfo.setDiagAccordRecords(diagAccordRecords);
			//[end]
			
			//[start] 设置病案首页护理信息
			HospitalVisitNurseInfo nurseInfo = new HospitalVisitNurseInfo();
			nurseInfo.setVisitGuid(visitGuid);
			if(hospitalVisitInfo.get("SICKDAYNUMBER")!=null){
				nurseInfo.setSickDayNumber((BigDecimal) hospitalVisitInfo.get("SICKDAYNUMBER"));
			}else{
				nurseInfo.setSickDayNumber(new BigDecimal(0));
			}
			if(hospitalVisitInfo.get("CRITICALDAYNUMBER")!=null){
				nurseInfo.setCriticalDayNumber((BigDecimal) hospitalVisitInfo.get("CRITICALDAYNUMBER"));
			}else{
				nurseInfo.setCriticalDayNumber(new BigDecimal(0));
			}
			if(hospitalVisitInfo.get("SPECIALNURSEDAYNUMBER")!=null){
				
				nurseInfo.setSpecialNurseDayNumber((BigDecimal) hospitalVisitInfo.get("SPECIALNURSEDAYNUMBER"));
			}else{
				nurseInfo.setSpecialNurseDayNumber(new BigDecimal(0));
			}
			if(hospitalVisitInfo.get("FIRSTLEVELNURSEDAYNUMBER")!=null){
				
				nurseInfo.setFirstLevelNurseDayNumber((BigDecimal) hospitalVisitInfo.get("FIRSTLEVELNURSEDAYNUMBER"));
			}else{
				nurseInfo.setFirstLevelNurseDayNumber(new BigDecimal(0));
			}
			nurseInfo.setSecondLevelNurseDayNumber((BigDecimal) hospitalVisitInfo.get("SECONDLEVELNURSEDAYNUMBER"));
			//[end]
			
			//[start] 设置病案首页输血信息
			//输血记录
			HospitalVisitInfusionBloodInfo infusionBloodInfo = new HospitalVisitInfusionBloodInfo();
			BigDecimal infusionBloodTimes = (BigDecimal) hospitalVisitInfo.get("SECONDLEVELNURSEDAYNUMBER");
			if (infusionBloodTimes != null) {
				infusionBloodInfo.setInfusionBloodTimes(infusionBloodTimes.intValue());
			}
			infusionBloodInfo
					.setInfusionBloodTotalVolume((BigDecimal) hospitalVisitInfo.get("INFUSIONBLOODTOTALVOLUME"));

			BigDecimal infusionBloodReactTimes = (BigDecimal) hospitalVisitInfo.get("INFUSIONBLOODREACTTIMES");
			if (infusionBloodReactTimes != null) {
				infusionBloodInfo.setInfusionBloodReactTimes(infusionBloodReactTimes.intValue());
			}
			infusionBloodInfo.setVisitGuid(basicInfo.getVisitGuid());
			
			
			/*List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();
			if(basicInfo.getMrId()!=null && basicInfo.getInHospitalDateTime()!=null && basicInfo.getOutHospitalDateTime()!=null) {
				BloodTransfusionVO bloodTransfusionVO = new BloodTransfusionVO();
				bloodTransfusionVO.setId(basicInfo.getMrId());
				bloodTransfusionVO.setInHospitalTime(basicInfo.getInHospitalDateTime());
				bloodTransfusionVO.setOutHospitalTime(basicInfo.getOutHospitalDateTime());
				infusionBloodRecords = this.getBloodTransfusionList(bloodTransfusionVO);
			}
			
			infusionBloodInfo.setInfusionBloodRecords(infusionBloodRecords);*/
			//[end]
//			HospitalVisitPressureSoreInfo pressureSoreInfo = new HospitalVisitPressureSoreInfo();
//			pressureSoreInfo.setPressureSoreTimes((BigDecimal) hospitalVisitInfo.get("PRESSURESORETIMES"));
			//[start] 设置病案首页费用信息
			HospitalVisitCostInfo visitCostInfo = new HospitalVisitCostInfo();
			visitCostInfo.setTotalCost((BigDecimal) hospitalVisitInfo.get("TOTALCOST"));
			visitCostInfo.setActuallyCost((BigDecimal) hospitalVisitInfo.get("ACTUALLYCOST"));
			List<Map<String, Object>> hospitalVisitCostRecords = export305DataMapper
					.getHospitalVisit305CostInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());
			for (Map<String, Object> hospitalVisitCostRecord : hospitalVisitCostRecords) {
				String medicalCostTypeName = (String) hospitalVisitCostRecord.get("COSTTYPENAME");
				String medicalCostTypeCode = (String) hospitalVisitCostRecord.get("COSTTYPECODE");
				BigDecimal costMoney = (BigDecimal) hospitalVisitCostRecord.get("COSTNUMBER");
				HospitalVisitCostRecord costRecord = new HospitalVisitCostRecord();
				costRecord.setMedicalCostTypeCode(medicalCostTypeCode);
				costRecord.setMedicalCostTypeName(medicalCostTypeName);
				costRecord.setCostMoney(costMoney);
				visitCostInfo.getCostRecords().add(costRecord);
			}
			//[end]
			cureInfo.setMedicalRecordQualityCode((String) hospitalVisitInfo.get("MEDICALRECORDQUALITYCODE"));
			cureInfo.setMedicalRecordQualityName((String) hospitalVisitInfo.get("MEDICALRECORDQUALITYNAME"));

			basicInfo.setMajorUnitCode((String) hospitalVisitInfo.get("MAJORUNITCODE"));
			basicInfo.setMajorUnitName((String) hospitalVisitInfo.get("MAJORUNITNAME"));

			basicInfo.setTroopServiceCode((String) hospitalVisitInfo.get("TROOPSERVICECODE"));
			basicInfo.setTroopServiceName((String) hospitalVisitInfo.get("TROOPSERVICENAME"));

			BigDecimal medicalSystemCode = (BigDecimal) hospitalVisitInfo.get("MEDICALSYSTEMCODE");
			if (medicalSystemCode != null) {
				basicInfo.setMedicalSystemCode(medicalSystemCode.intValue() + "");
			}
			basicInfo.setMedicalSystemName((String) hospitalVisitInfo.get("MEDICALSYSTEMNAME"));
			basicInfo.setIdTypeName((String) hospitalVisitInfo.get("IDTYPENAME"));
			basicInfo.setIdTypeCode((String) hospitalVisitInfo.get("IDTYPECODE"));

			System.out.println(hospitalVisitInfo);
			basicInfo.setCostTypeName((String) hospitalVisitInfo.get("COSTTYPENAME"));
			basicInfo.setCostTypeCode((String) hospitalVisitInfo.get("COSTTYPECODE"));
			
			BigDecimal injureCode = (BigDecimal)hospitalVisitInfo.get("TRAINING_INJURY_INDICATOR");
			if(injureCode!=null){
				basicInfo.setMilitaryTrainingInjuryCode(injureCode.toString());
			}
			
			//basicInfo.setMilitaryTrainingInjuryCode((String) hospitalVisitInfo.get("TRAINING_INJURY_INDICATOR"));
			basicInfo.setMilitaryTrainingInjuryName((String) hospitalVisitInfo.get("TRAININGINJURENAME"));
			BigDecimal jobStateCode = (BigDecimal) hospitalVisitInfo.get("JOBSTATECODE");
			if (jobStateCode != null) {
				basicInfo.setJobStateCode(jobStateCode.intValue() + "");
			}

			basicInfo.setJobStateName((String) hospitalVisitInfo.get("JOBSTATENAME"));
			
			//[start] 设置病案首页疾病诊断
			List<Map<String, Object>> hospitalVisitDiagInfos = export305DataMapper
					.getHospitalVisit305DiagInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());

			HospitalVisitDiseaseDiagInfo diseaseDiagInfo = new HospitalVisitDiseaseDiagInfo();
			diseaseDiagInfo.setVisitGuid(visitGuid);
			List<HospitalVisitDiseaseDiagRecord> diseaseDiagRecords = new ArrayList<HospitalVisitDiseaseDiagRecord>();
			for (Map<String, Object> hospitalVisitDiagInfo : hospitalVisitDiagInfos) {

				HospitalVisitDiseaseDiagRecord diseaseDiagRecord = new HospitalVisitDiseaseDiagRecord();
				diseaseDiagRecord.setDiagTypeCode((String) hospitalVisitDiagInfo.get("DIAGTYPECODE"));
				diseaseDiagRecord.setDiagTypeName((String) hospitalVisitDiagInfo.get("DIAGTYPENAME"));
				diseaseDiagRecord.setDiseaseDiagOriginalDesc((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
				diseaseDiagRecord.setDiseaseDiagCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
				if(hospitalVisitDiagInfo.get("DISEASEDIAGNAME")!=null && hospitalVisitDiagInfo.get("DISEASEDIAGCODE")!=null){
					
					diseaseDiagRecord.setDiseaseDiagName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME")+"-"+(String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
				}else{
					diseaseDiagRecord.setDiseaseDiagName(null);
				}
				String confirmedDateTimeStr = (String) hospitalVisitDiagInfo.get("CONFIRMEDDATETIME");
				
				
				if (confirmedDateTimeStr != null) {
					try {
						Date confirmedDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, confirmedDateTimeStr);
						diseaseDiagRecord.setConfirmedDateTime(confirmedDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				diseaseDiagRecord.setTreatResultCode((String) hospitalVisitDiagInfo.get("TREATRESULTCODE"));
				diseaseDiagRecord.setTreatResultName((String) hospitalVisitDiagInfo.get("TREATRESULTNAME"));
				BigDecimal diagSortIndex = (BigDecimal) hospitalVisitDiagInfo.get("DIAGSORTINDEX");
				if (diagSortIndex != null) {
					diseaseDiagRecord.setDiagSortIndex(diagSortIndex.intValue());
				}
				
				if(hospitalVisitDiagInfo.get("DIAGTYPECODE")!=null){
					if(("3").equals((String)hospitalVisitDiagInfo.get("DIAGTYPECODE"))){
						basicInfo.setMainDiseaseName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
						basicInfo.setMainDiseaseCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
					}
					
					if(hospitalVisitDiagInfo.get("DIAGTYPECODE")!=null && diagSortIndex != null){
						if("A".equals((String)hospitalVisitDiagInfo.get("DIAGTYPECODE")) && diagSortIndex.intValue()==1) {
							basicInfo.setSecondDiseaseName((String) hospitalVisitDiagInfo.get("DISEASEDIAGNAME"));
							basicInfo.setSecondDiseaseCode((String) hospitalVisitDiagInfo.get("DISEASEDIAGCODE"));
						}
					}
				}

				diseaseDiagRecord.setOperateMarkName((String) hospitalVisitDiagInfo.get("OPERATEMARKNAME"));
				BigDecimal operateMarkCode = (BigDecimal) hospitalVisitDiagInfo.get("OPERATEMARKCODE");
				if (operateMarkCode != null) {
					diseaseDiagRecord.setOperateMarkCode("" + operateMarkCode.intValue());
				}

				diseaseDiagRecord.setTreatDayNumber((BigDecimal) hospitalVisitDiagInfo.get("TREATDAYNUMBER"));
				diseaseDiagRecords.add(diseaseDiagRecord);
			}
			Collections.sort(diseaseDiagRecords, new HospitalVisitDiseaseDiagRecord.DiseaseDiagRecordComparator());

			diseaseDiagInfo.setDiseaseDiagRecords(diseaseDiagRecords);
			//[end]
			
			//[start] 设置病案首页手术信息
			List<Map<String, Object>> hospitalVisitOperateInfos = export305DataMapper
					.getHospitalVisit305OperateInfoByOracle(basicInfo.getMrId(), basicInfo.getVisitNumber().intValue());

			HospitalVisitOperateInfo operateInfo = new HospitalVisitOperateInfo();
			operateInfo.setVisitGuid(visitGuid);
			List<HospitalVisitOperateRecord> operateRecords = new ArrayList<HospitalVisitOperateRecord>();
			for (Map<String, Object> hospitalVisitOperateInfo : hospitalVisitOperateInfos) {
					
				HospitalVisitOperateRecord operateRecord = new HospitalVisitOperateRecord();
				operateRecord.setOperateOriginalDesc((String) hospitalVisitOperateInfo.get("OPERATENAME"));
				operateRecord.setOperateCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
				operateRecord.setOperateName((String) hospitalVisitOperateInfo.get("OPERATENAME")+"-"+(String) hospitalVisitOperateInfo.get("OPERATECODE"));

				operateRecord.setIncisionLevelCode((String) hospitalVisitOperateInfo.get("INCISIONLEVELCODE"));
				operateRecord.setIncisionLevelName((String) hospitalVisitOperateInfo.get("INCISIONLEVELNAME"));
				operateRecord.setCicatrizeTypeCode((String) hospitalVisitOperateInfo.get("CICATRIZETYPECODE"));
				//operateRecord.setIncisionLevelName((String) hospitalVisitOperateInfo.get("CICATRIZETYPENAME"));
				operateRecord.setCicatrizeTypeName((String) hospitalVisitOperateInfo.get("CICATRIZETYPENAME"));
				BigDecimal operateSortIndex = (BigDecimal) hospitalVisitOperateInfo.get("OPSINDEX");
				if (operateSortIndex != null) {
					operateRecord.setOperateSortIndex(operateSortIndex.intValue());
					if(1==operateSortIndex.intValue()){
						basicInfo.setFirstOperationName((String) hospitalVisitOperateInfo.get("OPERATENAME"));
						basicInfo.setFirstOperationCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
					}else if(2==operateSortIndex.intValue()){
						basicInfo.setSecondOperationName((String) hospitalVisitOperateInfo.get("OPERATENAME"));
						basicInfo.setSecondOperationCode((String) hospitalVisitOperateInfo.get("OPERATECODE"));
					}
				}
				String operateDateStr = (String) hospitalVisitOperateInfo.get("OPERATEDATE");
				if (operateDateStr != null) {
					try {
						Date operateDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, operateDateStr);
						operateRecord.setOperateStartDate(operateDate);
						operateRecord.setOperateEndDate(operateDate);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				operateRecord.setAnaesthesiaTypeCode((String) hospitalVisitOperateInfo.get("ANAESTHESIATYPECODE"));
				operateRecord.setAnaesthesiaTypeName((String) hospitalVisitOperateInfo.get("ANAESTHESIATYPENAME"));
				List<HospitalVisitOperateWorker> operateWorkers = new ArrayList<HospitalVisitOperateWorker>();
				HospitalVisitOperateWorker operateWorker1 = new HospitalVisitOperateWorker();
				operateWorker1.setProfessionTitleName("手术医师");
				operateWorker1.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("OPERATOR"));
				operateWorkers.add(operateWorker1);

				HospitalVisitOperateWorker operateWorker2 = new HospitalVisitOperateWorker();
				operateWorker2.setProfessionTitleName("第一助手");
				operateWorker2.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("FIRST_ASSISTANT"));
				operateWorkers.add(operateWorker2);

				HospitalVisitOperateWorker operateWorker3 = new HospitalVisitOperateWorker();
				operateWorker3.setProfessionTitleName("第二助手");
				operateWorker3.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("SECOND_ASSISTANT"));
				operateWorkers.add(operateWorker3);

				HospitalVisitOperateWorker operateWorker4 = new HospitalVisitOperateWorker();
				operateWorker4.setProfessionTitleName("麻醉医师");
				operateWorker4.setMedicalWorkerName((String) hospitalVisitOperateInfo.get("ANESTHESIA_DOCTOR"));
				operateWorkers.add(operateWorker4);
				operateRecord.setOperateWorkers(operateWorkers);
				operateRecords.add(operateRecord);
			}
			
			Collections.sort(operateRecords,new HospitalVisitOperateRecord());
			operateInfo.setOperateRecords(operateRecords);
			//[end]
			
			//[start] 设置病案首页转科信息
			List<Map<String, Object>> hospitalVisitTransferDeptInfos = export305DataMapper
					.getHospitalVisit305TransferDeptInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitTransferDeptInfo transferDeptInfo = new HospitalVisitTransferDeptInfo();
			transferDeptInfo.setVisitGuid(visitGuid);
			List<HospitalVisitTransferDeptRecord> transferDeptRecords = new ArrayList<HospitalVisitTransferDeptRecord>();
			for (Map<String, Object> hospitalVisitTransferDeptInfo : hospitalVisitTransferDeptInfos) {

				HospitalVisitTransferDeptRecord transferDeptRecord = new HospitalVisitTransferDeptRecord();
				transferDeptRecord.setOutDeptCode((String) hospitalVisitTransferDeptInfo.get("OUTDEPTCODE"));
				transferDeptRecord.setOutDeptName((String) hospitalVisitTransferDeptInfo.get("OUTDEPTNAME"));

				transferDeptRecord.setInDeptCode((String) hospitalVisitTransferDeptInfo.get("INDEPTCODE"));
				transferDeptRecord.setInDeptName((String) hospitalVisitTransferDeptInfo.get("INDEPTNAME"));
				String transferDeptInDateTimeStr = (String) hospitalVisitTransferDeptInfo.get("TRANSFERDEPTINDATETIME");
				
				if (transferDeptInDateTimeStr != null) {
					if (transferDeptInDateTimeStr != null) {
						try {
							Date transferDeptInDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
									transferDeptInDateTimeStr);
							transferDeptRecord.setTransferDeptInDateTime(transferDeptInDateTime);
							transferDeptRecord.setTransferDeptDateTime(transferDeptInDateTime);
						} catch (ParseException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
				
				String transferDeptOutDateTimeStr = (String) hospitalVisitTransferDeptInfo
						.get("TRANSFERDEPTOUTDATETIME");
				if (transferDeptOutDateTimeStr != null) {
					try {
						Date transferDeptOutDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								transferDeptOutDateTimeStr);
						transferDeptRecord.setTransferDeptOutDateTime(transferDeptOutDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				transferDeptRecords.add(transferDeptRecord);
			}
			transferDeptInfo.setTransferDeptRecords(transferDeptRecords);
			
			//[end]
			/*List<Map<String, Object>> hospitalVisitTransferBloodInfos = export305DataMapper
					.getHospitalVisit305TransferBloodInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());*/
			//List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();
			
		
		//	List<HospitalVisitInfusionBloodRecord> infusionBloodRecords = new ArrayList<HospitalVisitInfusionBloodRecord>();

			//[start] 设置病案首页医嘱信息
			List<Map<String, Object>> hospitalVisitDoctorAdviceInfos = export305DataMapper
					.getHospitalVisit305DoctorAdviceTemporaryInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitDoctorAdviceTemporaryInfo doctorAdviceTemporaryInfo = new HospitalVisitDoctorAdviceTemporaryInfo();
			doctorAdviceTemporaryInfo.setVisitGuid(visitGuid);
			Map<String, HospitalVisitDoctorAdviceTemporaryRecord> doctorAdviceTemporaryRecordMap = new HashMap<String, HospitalVisitDoctorAdviceTemporaryRecord>();
			for (Map<String, Object> hospitalVisitDoctorAdviceInfo : hospitalVisitDoctorAdviceInfos) {
				String detpCode = (String) hospitalVisitDoctorAdviceInfo.get("DEPTCODE");
				HospitalVisitDoctorAdviceTemporaryRecord doctorAdviceTemporaryRecord = null;
				if (doctorAdviceTemporaryRecordMap.containsKey(detpCode)) {
					doctorAdviceTemporaryRecord = doctorAdviceTemporaryRecordMap.get(detpCode);
				} else {
					doctorAdviceTemporaryRecord = new HospitalVisitDoctorAdviceTemporaryRecord();
					doctorAdviceTemporaryRecord.setMrId(basicInfo.getMrId());
					doctorAdviceTemporaryRecord.setPatientName(basicInfo.getPatientName());
					doctorAdviceTemporaryRecord.setDeptName((String) hospitalVisitDoctorAdviceInfo.get("DEPT_NAME"));
					doctorAdviceTemporaryRecordMap.put(detpCode, doctorAdviceTemporaryRecord);
				}

				HospitalVisitDoctorAdviceTemporaryItem doctorAdviceTemporaryItem = new HospitalVisitDoctorAdviceTemporaryItem();

				String presupposeDateTimeStr = (String) hospitalVisitDoctorAdviceInfo.get("PRESUPPOSEDATETIME");
				if (presupposeDateTimeStr != null) {
					try {
						Date presupposeDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE, presupposeDateTimeStr);
						doctorAdviceTemporaryItem.setPresupposeDateTime(presupposeDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

				StringBuilder sbDoctorAdviceContent = new StringBuilder();

				String orderText = (String) hospitalVisitDoctorAdviceInfo.get("ORDER_TEXT");
				if (orderText != null) {
					sbDoctorAdviceContent.append(orderText);
				}

				BigDecimal dosag = (BigDecimal) hospitalVisitDoctorAdviceInfo.get("DOSAGE");

				String dosagUnits = (String) hospitalVisitDoctorAdviceInfo.get("DOSAGE_UNITS");
				if (dosag != null && dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosag + dosagUnits);
				} else if (dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosagUnits);
				} else if (dosag != null) {
					sbDoctorAdviceContent.append("   " + dosag);
				}

				String administration = (String) hospitalVisitDoctorAdviceInfo.get("ADMINISTRATION");
				if (administration != null) {
					sbDoctorAdviceContent.append("   " + administration);
				}
				doctorAdviceTemporaryItem.setDoctorAdviceContent(sbDoctorAdviceContent.toString());
				doctorAdviceTemporaryItem.setDoctorName((String) hospitalVisitDoctorAdviceInfo.get("DOCTORNAME"));
				doctorAdviceTemporaryItem.setNurseName((String) hospitalVisitDoctorAdviceInfo.get("NURSENAME"));
				String executionDateTimeStr = (String) hospitalVisitDoctorAdviceInfo.get("EXECUTIONDATETIME");
				if (executionDateTimeStr != null) {
					try {
						Date executionDateTime = DateUtil.dateParse("HH:mm", executionDateTimeStr);
						doctorAdviceTemporaryItem.setExecutionDateTime(executionDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				doctorAdviceTemporaryRecord.getDoctorAdviceTemporaryItems().add(doctorAdviceTemporaryItem);
			}
			for (HospitalVisitDoctorAdviceTemporaryRecord hospitalVisitDoctorAdviceTemporaryRecord : doctorAdviceTemporaryRecordMap
					.values()) {
				doctorAdviceTemporaryInfo.getDoctorAdviceTemporaryRecords()
						.add(hospitalVisitDoctorAdviceTemporaryRecord);
			}

			List<Map<String, Object>> hospitalVisitDoctorAdviceStandingInfos = export305DataMapper
					.getHospitalVisit305DoctorAdviceStandingInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());

			HospitalVisitDoctorAdviceStandingInfo doctorAdviceStandingInfo = new HospitalVisitDoctorAdviceStandingInfo();
			doctorAdviceStandingInfo.setVisitGuid(visitGuid);
			Map<String, HospitalVisitDoctorAdviceStandingRecord> doctorAdviceStandingRecordMap = new HashMap<String, HospitalVisitDoctorAdviceStandingRecord>();
			for (Map<String, Object> hospitalVisitDoctorAdviceStandingInfo : hospitalVisitDoctorAdviceStandingInfos) {

				String detpCode = (String) hospitalVisitDoctorAdviceStandingInfo.get("DEPTCODE");
				HospitalVisitDoctorAdviceStandingRecord doctorAdviceStandingRecord = null;
				if (doctorAdviceStandingRecordMap.containsKey(detpCode)) {
					doctorAdviceStandingRecord = doctorAdviceStandingRecordMap.get(detpCode);
				} else {
					doctorAdviceStandingRecord = new HospitalVisitDoctorAdviceStandingRecord();
					doctorAdviceStandingRecord.setMrId(basicInfo.getMrId());
					doctorAdviceStandingRecord.setPatientName(basicInfo.getPatientName());
					doctorAdviceStandingRecord.setDeptName((String) hospitalVisitDoctorAdviceStandingInfo.get("DEPT_NAME"));
					doctorAdviceStandingRecordMap.put(detpCode, doctorAdviceStandingRecord);
				}

				HospitalVisitDoctorAdviceStandingItem doctorAdviceStandingItem = new HospitalVisitDoctorAdviceStandingItem();

				String doctorAdviceStartDateTimeStr = (String) hospitalVisitDoctorAdviceStandingInfo
						.get("DOCTORADVICESTARTDATETIME");
				if (doctorAdviceStartDateTimeStr != null) {
					try {
						Date doctorAdviceStartDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								doctorAdviceStartDateTimeStr);
						doctorAdviceStandingItem.setDoctorAdviceStartDateTime(doctorAdviceStartDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

				StringBuilder sbDoctorAdviceContent = new StringBuilder();

				String orderText = (String) hospitalVisitDoctorAdviceStandingInfo.get("ORDER_TEXT");
				if (orderText != null) {
					sbDoctorAdviceContent.append(orderText);
				}

				BigDecimal dosag = (BigDecimal) hospitalVisitDoctorAdviceStandingInfo.get("DOSAGE");

				String dosagUnits = (String) hospitalVisitDoctorAdviceStandingInfo.get("DOSAGE_UNITS");
				if (dosag != null && dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosag + dosagUnits);
				} else if (dosagUnits != null) {
					sbDoctorAdviceContent.append("   " + dosagUnits);
				} else if (dosag != null) {
					sbDoctorAdviceContent.append("   " + dosag);
				}

				String administration = (String) hospitalVisitDoctorAdviceStandingInfo.get("ADMINISTRATION");
				if (administration != null) {
					sbDoctorAdviceContent.append("   " + administration);
				}

				String frequency = (String) hospitalVisitDoctorAdviceStandingInfo.get("FREQUENCY");
				if (frequency != null) {
					sbDoctorAdviceContent.append("   " + frequency);
				}
				
				doctorAdviceStandingItem.setDoctorAdviceContent(sbDoctorAdviceContent.toString());
				doctorAdviceStandingItem.setDoctorAdviceStartDoctorName(
						(String) hospitalVisitDoctorAdviceStandingInfo.get("DOCTORADVICESTARTDOCTORNAME"));
				doctorAdviceStandingItem.setDoctorAdviceStartNurseName(
						(String) hospitalVisitDoctorAdviceStandingInfo.get("DOCTORADVICESTARTNURSENAME"));
				String doctorAdviceEndDateTimeStr = (String) hospitalVisitDoctorAdviceStandingInfo.get("DOCTORADVICEENDDATETIME");
				
				if (doctorAdviceEndDateTimeStr != null) {
					try {
						Date doctorAdviceEndDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,
								doctorAdviceEndDateTimeStr);
						doctorAdviceStandingItem.setDoctorAdviceEndDateTime(doctorAdviceEndDateTime);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				doctorAdviceStandingRecord.getDoctorAdviceStandingItems().add(doctorAdviceStandingItem);
			}

			for (HospitalVisitDoctorAdviceStandingRecord hospitalVisitDoctorAdviceStandingRecord : doctorAdviceStandingRecordMap
					.values()) {
				doctorAdviceStandingInfo.getDoctorAdviceStandingRecords().add(hospitalVisitDoctorAdviceStandingRecord);
			}
			//[end]
			/*List<Map<String, Object>> hospitalVisitExaminationReportInfos = export305DataMapper
					.getHospitalVisit305InspectionReportInfoByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().intValue());*/
			
			//[start] 设置病案检验报告单信息
			HospitalVisitExaminationReportsInfo examinationReportsInfo = new HospitalVisitExaminationReportsInfo();
			examinationReportsInfo.setVisitGuid(visitGuid);
			try {
				examinationReportsInfo = getExaminationReportsInfo( hospitalVisitInfo,visitGuid);
			} catch (Exception e) {
				examinationReportsInfo=new HospitalVisitExaminationReportsInfo();
				examinationReportsInfo.setVisitGuid(visitGuid);
			}
			//[end]
			
			//--------------------病程记录 begin-----------------
			HospitalVisitProgressNote progressNote = new HospitalVisitProgressNote();
			progressNote.setVisitGuid(visitGuid);
			List<String> fileNameList = Lists.newArrayList();
			String progressNoteFolder = StringUtil.ftpFolderGenerator((String)hospitalVisitInfo.get("MRID"),((BigDecimal)hospitalVisitInfo.get("VISITNUMBER")).intValue());
			
			String localProgressNoteFolder =myConfig.getProgressNoteDir()+visitGuid+"/";
			File progressNoteFile = new File(localProgressNoteFolder);
			if(!progressNoteFile.isDirectory()){
				progressNoteFile.mkdirs();
			}
			
			try {
				fileNameList = FtpClientUtil.downFile(myConfig.getFtpHost(),myConfig.getFtpPort(),myConfig.getFtpUsername(),myConfig.getFtpPassword(), progressNoteFolder, localProgressNoteFolder);
				System.out.println(fileNameList);
			} catch (Exception e) {
				fileNameList = Lists.newArrayList();
				log.error("提取病程记录出现问题:MRID="+(String)hospitalVisitInfo.get("MRID")+" 错误信息:"+e.getMessage());
			} 
			progressNote.setProgressList(fileNameList);
			//--------------------病程记录  end-----------------
			
			
			//药物过敏
			HospitalVisitDrugAllergyInfo drugAllergyInfo = new  HospitalVisitDrugAllergyInfo();
			List<HospitalVisitDrugAllergyRecord> drugAllergyRecords = new ArrayList<HospitalVisitDrugAllergyRecord>();
			drugAllergyInfo.setVisitGuid(visitGuid);
			if(hospitalVisitInfo.get("ALERGYDYUGS")!=null){
				HospitalVisitDrugAllergyRecord drugAllergyRecord = new HospitalVisitDrugAllergyRecord();
				drugAllergyRecord.setDrugAllergyName((String)hospitalVisitInfo.get("ALERGYDYUGS"));
				drugAllergyRecords.add(drugAllergyRecord);
			}
			drugAllergyInfo.setDrugAllergyRecords(drugAllergyRecords);
			
			HospitalVisitInfectionInfo infectionInfo = new HospitalVisitInfectionInfo();
			infectionInfo.setVisitGuid(visitGuid);
			List<Map<String,Object>> infectionRecords = export305DataMapper.queryHospitalInspectionByOracle(basicInfo.getMrId(),
							basicInfo.getVisitNumber().toString());
			if(CollectionUtils.isEmpty(infectionRecords)){
				infectionInfo.setInfectionRecords(new ArrayList<HospitalVisitInfectionRecord>());
			}else{
			    List<HospitalVisitInfectionRecord> infectionRecordList = appendInfectionRecord(infectionRecords);
			    infectionInfo.setInfectionRecords(infectionRecordList);
			}
			
			
			hospitalVisitFillInfo.put("firstGuid", basicInfo.getVisitGuid());
			//基本信息
			hospitalVisitFillInfo.put("basicInfo", basicInfo);
			//治疗信息
			hospitalVisitFillInfo.put("cureInfo", cureInfo);
			//疾病信息
			hospitalVisitFillInfo.put("diseaseDiagInfo", diseaseDiagInfo);
			//手术信息
			hospitalVisitFillInfo.put("operateInfo", operateInfo);
			//转科记录
			hospitalVisitFillInfo.put("transferDeptInfo", transferDeptInfo);
			//护理信息(一级护理天数、....)
			hospitalVisitFillInfo.put("nurseInfo", nurseInfo);
			//hospitalVisitFillInfo.put("intensiveCareInfo", intensiveCareInfo);
			//输血记录
			hospitalVisitFillInfo.put("infusionBloodInfo", infusionBloodInfo);
//			hospitalVisitFillInfo.put("pressureSoreInfo", pressureSoreInfo);
			//临时医嘱
			hospitalVisitFillInfo.put("doctorAdviceTemporaryInfo", doctorAdviceTemporaryInfo);
			//长期医嘱
			hospitalVisitFillInfo.put("doctorAdviceStandingInfo", doctorAdviceStandingInfo);
			//检验报告单
			hospitalVisitFillInfo.put("examinationReportsInfo", examinationReportsInfo);
			//病程记录(表单)
			hospitalVisitFillInfo.put("progressNote", progressNote);
			//费用记录
			hospitalVisitFillInfo.put("visitCostInfo", visitCostInfo);
			
			//医院感染
			hospitalVisitFillInfo.put("infectionInfo", infectionInfo);
			
			hospitalVisitFillInfo.put("drugAllergyInfo", drugAllergyInfo);
			hospitalVisitFillInfos.add(hospitalVisitFillInfo);
		}
		return new Result(true, "查询成功", hospitalVisitFillInfos);
	}

	@TargetDataSource(name = "ds1")
	@Transactional
	@Override
	public void insertHospitalVisitRecords(List<Map<String, Object>> datas, User user, String visitGuid) {
		// TODO Auto-generated method stub
		for (Map<String, Object> data : datas) {
			insertHospitalVisitRecord(data, user,visitGuid);
		}
	}
	
	public int insertHospitalVisitRecord(Map<String, Object> data, User user,String visitGuid) {
		HospitalVisitBasicInfo basicInfo = (HospitalVisitBasicInfo) data.get("basicInfo");
		List<Map<String, Object>> hospitals = exportDataMapper.getHospitalByCode(basicInfo.getHospitalCode());
		
		if (!hospitals.isEmpty()) {
			basicInfo.setHospitalName((String) hospitals.get(0).get("name"));
		}
		
		String filePath = myConfig.getHospitalVisitJsonPath() + StringUtil.getLocalPath(basicInfo.getVisitGuid());
//		String versionFilePath = myConfig.getHospitalVisitJsonVersionPath()
//				+ StringUtil.getLocalPath(basicInfo.getVisitGuid());
		String versionFilePath = myConfig.getHospitalVisitJsonVersionPath()+basicInfo.getVisitGuid()+"/";
		String fileName = basicInfo.getVisitGuid() + ".json";
		//String versionFileName = basicInfo.getVisitGuid() + "-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date())
		//		+ ".json";
		String versionFileName =DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";
		data.put("userId", user.getLoginName());
		data.put("userName", user.getName());
		
		String jsonMapJson = JsonUtil.objectToJson(data);
		
		try {
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
		} catch (IOException e) {
			e.printStackTrace();
		}

		List<String> hbList = hospNoteBasicJsonMapper.getHospBasicJsonByFirstGuid("\"" + visitGuid + "\"");
		if (null == hbList || hbList.size() == 0) {
			hospNoteBasicJsonMapper.insert(jsonMapJson);
		} else {
			hospNoteBasicJsonMapper.updateHospNoteBasicJsonByFirstGuid(jsonMapJson, "\"" +visitGuid + "\"");
		}
	
		HospNoteVersion hospNoteVersion = new HospNoteVersion();
		hospNoteVersion.setCreateTime(new Date());
		hospNoteVersion.setFirstGuid(basicInfo.getVisitGuid());
		hospNoteVersion.setFileName(versionFileName);
		hospNoteVersion.setOperator(user.getName());
		hospNoteVersionMapper.insert(hospNoteVersion);
		
		return 0;
		
		
	}

	@Override
	public List<Map<String, Object>> getHospitalVisit305InfoByOracleByMrIdAndVisitNumber(String mrId,
			Integer visitNumber) {
		return export305DataMapper.getHospitalVisit305InfoByOracleByMrIdAndVisitNumber(mrId, visitNumber);
	}
	
	
	
	
	
	

}








